Error in using "shading interp" with logarithmic colorscale
Show older comments
I want to do a shading interp to my plot. It works fine when I use linear(default) colorscale, but when I set the colorscale to "log", the plot on that ax disappeared.
- do shading interp earlier
ax2 = axes;
m_proj('miller','long',[lon1 lon2],'lat',[lat1 lat2]); %m_proj is function from m_map package
m_pcolor(X,Y,delta_p); % from m_map package
shading interp;
m_grid('linest','none','tickdir','out','box','fancy','fontsize',10); % from m_map package
axis equal; % "merge" the plots on ax1 and ax2
set(ax2,'ColorScale','log');
% >>Warning: Error creating or updating Surface
% Error in value of property <a
% href="matlab:helpUtils.reference.showPropertyHelp('matlab.graphics.primitive.Surface','CData');")">CData</a>
% DataSpace or ColorSpace transform method failed
Then the plot on ax2 disappeared
- do shading interp later
ax2 = axes;
m_proj('miller','long',[lon1 lon2],'lat',[lat1 lat2]);
m_pcolor(X,Y,delta_p);
m_grid('linest','none','tickdir','out','box','fancy','fontsize',10);
axis equal;
shading interp;
%>> Warning: Error creating or updating Patch
%Error in value of property <a
%href="matlab:helpUtils.reference.showPropertyHelp('matlab.graphics.primitive.Patch','FaceVertexCData');")">FaceVertexCData</a>
% Number of colors must equal number of vertices
%%%%%% This warning appears 5 times. Despite of this warning, shading interp still works
set(ax2,'ColorScale','log');
Then I received the same warning again, but this time the whole plot on ax2 disappeared, only left with the axes.

Then I tried first setting to log scale then shading interp:
ax2 = axes;
m_proj('miller','long',[lon1 lon2],'lat',[lat1 lat2]);
m_pcolor(X,Y,delta_p);
m_grid('linest','none','tickdir','out','box','fancy','fontsize',10);
set(ax2,'ColorScale','log');
s1=findobj(ax2,'Type','surf');
set(s1,'FaceColor','interp')
But I still got the Dataspace/Color Space transform warning, and the plot still disappeared.
Other answers to this issue suggest replace numbers that are close to 0 with NaN, I tried but it still didn't work.
delta_p(delta_p<1e-04)=NaN;
7 Comments
G A
on 24 May 2021
doc shading
It says: The shading function controls the color shading of surface and patch graphics objects.
Voss
on 24 May 2021
Related: maybe m_pcolor creates a surface object.
Siyi Zhang
on 25 May 2021
G A
on 25 May 2021
pcolor(peaks);
set(gca,'ColorScale','log');
colormap(parula(256));
shading flat;
works
pcolor(peaks);
set(gca,'ColorScale','linear');
colormap(parula(256));
shading interp
works
pcolor(peaks);
set(gca,'ColorScale','log');
colormap(parula(256));
shading interp;
% Warning: Error creating or updating Surface
% Error in value of property CData
% DataSpace or ColorSpace transform method failed.
does not work
Siyi Zhang
on 26 May 2021
I don't think that is a bug. It is just not possible to do in Matlab now. See similar question about transparency.
Siyi Zhang
on 27 May 2021
Answers (0)
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!