MATLAB: Do I get “Error updating Line. DataSpace or ColorSpace transform method failed” when I use log-scale plot

brushcolorspacedatadatascalelinkdatalinkinglogMATLABscale

Why do I get "Error updating Line. DataSpace or ColorSpace transform method failed" when I use log-scale, data linking and brushing?
Warning: Error updating Line.
DataSpace or ColorSpace transform method failed
Reproduction steps:
1. Run the code below
2. Brush the data in the left axis (linear-scale)
3. Expect the corresponding data points to be highlighted in the right axis (log-scale)
>> X1 = randn(100,1);
>> Y1 = randn(100,1);
>>
>> f = figure;
>> a1 = axes('Parent',f,'Position',[0.05 0.1 0.4 0.55]);
>> a2 = axes('Parent',f,'Position',[0.55 0.1 0.4 0.55]);
>>
>> h.fig = f;
>> h.ax(1) = a1;
>> h.ax(2) = a2;
>>
>>h.l(1) = plot(h.ax(1), X1, Y1, '.','XDataSource', 'X1');
>>h.l(2) = plot(h.ax(2), X1, Y1, '.','XDataSource', 'X1');
>> set(h.ax(2), 'XScale', 'log');
>>
>> linkdata on
>> brush on

Best Answer

Even though the data on the left and right axes have one-to-one mapping (they are basically the same data X1 vs. Y1), they are plotted in different scale (linear-scale vs. log-scale).
The data "X1" contains values that are very close to 0, and therefore causing an "-Inf" value that cannot be plotted when it's mapped from the right axes to the left axes.
To workaround this, you can either:
1. Replace values of "X1" that are very close to 0 with NaN:
>> X1(X1 < 0.00001) = NaN;
2. Remove the data point:
>> idx = (X1 < 0.00001);
>> X1(idx) = [];
>> Y1(idx) = [];
3. Use linear scaling for both the left and right axes