MatLab: Weird display of logarithmic z-axis and bar3

折月煮酒 提交于 2019-12-11 03:14:55

问题


I want to display a 3d histogram using bar3plot. Using linear scales with respect to x-, y-, and z-axis gives the following result:

However, since the z-values have a very large interval I want to use a logarithmic z-axis such that the lower z-values are also visible. However, setting the z-axis to logarithmic with set(gca, 'ZScale', 'log'); yields the following plot, which does not look good:

Is there some extra option I need to set or is it a known bug?

Thanks in advance!


回答1:


This is a fairly common problem with log axis in Matlab with non standard plotting functions or modifications to plots, eg trying to use transparency with log axis

The Problem

The plot generated by bar3 requires the OpenGL renderer which doesn't support logarithmic axis.

The Solution

Mimic log axis by transforming data and setting tick marks / labels

the following creates the plot with log axis to get tick marks and lables, clears the axis then starts again plotting the log of the data with transformed tick marks and labels.

bar3(Z);
set(gca,'Zscale','log')
ticks=get(gca,'Ztick');
ticklabel=str2num(get(gca,'ZtickLabel'));
set(gca,'Zscale','linear')
cla

bar3(log(Z));
set(gca,'Ztick',log(ticks));set(gca,'ZtickLabel',10.^ticklabel)

only the formatting of the tick labels is lost.

This method does not work well for values in the range 0-1 with bar3 as the plot is inverted and negative causes issues with log in either case further transforms would be required. however looking at the data in the plots given this should not be an issue.



来源:https://stackoverflow.com/questions/23824362/matlab-weird-display-of-logarithmic-z-axis-and-bar3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!