1

When z values are 0 with a log ZScale, the plot is rendered incorrectly. That's coherent, because log10(0) = -inf.

Example:

Y = cool(7);
bar3(Y)
set(gca,'ZScale','log')

But how can I remove this 0 bars from the plot?

A solution given by Mathworks (http://www.mathworks.nl/support/solutions/en/data/1-2VFT6X/?product=ML&solution=1-2VFT6X) is the following:

Y = cool(7);
bar3(Y)
set(gca,'ZScale','log')

llim = .1;
h = get(gca,'Children');
for i = 1:length(h)
    ZData = get(h(i), 'ZData');
    ZData(ZData==0) = llim;
    set(h(i), 'ZData', ZData);
end

This solution replaces 0 values by 0.1 (then log10(0.1) = -1) but I want to remove 0 bars, not draw -1 bars.

Also I tried set to NaN all 0 values How to hide zero values in bar3 plot in MATLAB but set ZScale to log does not like it.

Any suggestion?

Thanks in advance

EDIT: The easiest solution that I see is to apply the logarithmic scale manually:

Y = cool(7);    
Y = log10(Y);
Y(Y==-inf)=NaN; 
bar3(Y)
Community
  • 1
  • 1
d1eg0
  • 23
  • 6
  • Is it possible to create a new vector where the zero values have been removed, like in this newsreader post? http://www.mathworks.com/matlabcentral/newsreader/view_thread/305649 – darthbith Aug 05 '13 at 12:28
  • That's possible with vectors, but in my case ZData values are a matrix, I can't reshape the ZData values matrix removing zero values in a new matrix. – d1eg0 Aug 06 '13 at 08:36

1 Answers1

0

If you're fine replacing log z-values with 0.1, you can replace all zero values with 10^0.1, so when logged, they become 0.1.

So,

Y = cool(7);
Y(Y==0) = 10^0.1;
bar3(Y)
set(gca,'ZScale','log')

This will preserve the log-scale axes tick marks and labels.

Gordon Bean
  • 4,272
  • 1
  • 32
  • 47