在条形图中设置条形的透明度并将y轴设置为对数比例-但两者似乎在MATLAB中都不起作用 [英] Set the transparency of bars in a bar plot and set the y-axis to a log scale - but both don't seem to work in MATLAB

查看:137
本文介绍了在条形图中设置条形的透明度并将y轴设置为对数比例-但两者似乎在MATLAB中都不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中,我想将条形图中的条形透明度设置为0.3,并将y轴设置为对数刻度-但两者似乎都不起作用...

In MATLAB, I want to set the transparency of bars in a bar plot to 0.3 and set the y-axis to a log scale - but both don't seem to work...

subplot('Position',[0.15 0.7 0.45 0.15]);
data = [1 2 5 4 7 4 1];
B = bar(data,'g');
ch = get(B,'child');
set(ch,'facea',.3)

那很好,但是再加上:

set(gca,'YScale','log');

,透明度设置不起作用.有任何想法吗?谢谢!

and the transparency setting doesn't work. Any ideas? Thanks!

推荐答案

对数刻度轴和透明度在Matlab中无法一起使用

Log Scale axis and Transparency do not work together in Matlab

OpenGl渲染器(必须用于透明度)不支持对数轴-自2010b起,这显然在文档中,并且也提到了

OpenGl renderer, (which must be used for the transparency) does not support logarithmic axis - this is apparently in the documentation as of 2010b and is also mentioned here

通过转换数据来模拟对数轴&设置Yaxis刻度

Mimic Log axis by transforming data & setting Yaxis ticks

下面的代码使条形图具有对数轴,获取所需的属性,清除轴,然后使用该信息模拟对数轴.
代码:

the code below makes the bar plot with log axis, gets the required properties, clears the axis and then uses the information to mimic the log axis
code:

subplot('Position',[0.15 0.7 0.45 0.15]);
data = [1 2 5 4 7 4 1];
B = bar(data,'g');
set(gca,'Yscale','log')
ticks=get(gca,'Ytick');
ticklabel=str2num(get(gca,'YtickLabel'));
set(gca,'Yscale','linear')
cla

B = bar(log(data),'g');
set(gca,'Ytick',log(ticks));set(gca,'YtickLabel',10.^ticklabel)
ch = get(B,'child');
set(ch,'facea',.3)

唯一的损失是刻度标签的格式.
最终,我几乎不能保证在将它应用于负面数据时,尽管几乎可以肯定会发出警告并且不能正常工作!

The only loss is the formatting of tick labels.
Finally I cant guarantee anything when applied to negative data, although it will almost certainly throw a warning and not work properly!

这篇关于在条形图中设置条形的透明度并将y轴设置为对数比例-但两者似乎在MATLAB中都不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆