Matlab - 右侧y轴没有显示并且在网格上方显示

时间:2016-02-23 05:15:39

标签: matlab

我正在用直方图绘制数据。这是下图中的结果:

enter image description here

如您所见,右侧y轴未显示,我不明白为什么。

我对这个情节的代码:

x = load('performances.txt');

% Get Runtimes
for i = 1:6
time_seq(1:5,i) = x((i-1)*5+1:i*5,3);
time_gpu(1:5,i) = x((i-1)*5+1:i*5,4);
speedup(1:5,i) = time_seq(1:5,i)./time_gpu(1:5,i);
end

% X axis
sizeArray = [1024 10240 102400 1024000 10240000 102400000]
figure(1);

% Get Histogram
h = bar(log10(sizeArray),log10(speedup(1:5,:)')); % get histogram

% Log10 for x-axis and xtick
set(gca,'Xtick',log10(1024):1:log10(1.024*10^8))
set(gca,'Xticklabel',10.^get(gca,'Xtick'));
set(h(1),'facecolor','b');
set(h(2),'facecolor','r');
set(h(3),'facecolor','g');
set(h(4),'facecolor','k');
set(h(5),'facecolor','m');
hPatch = findobj(h,'Type','patch');
set(hPatch,'facealpha',0.4);
grid on;

% Size of WorkGroup
h = legend('N=16','N=32','N=64','N=128','N=256');
v = get(h,'title');
set(v,'string','WorkGroup size');

% Place legend
rect = [0.6,0.3,0.2,0.2];
set(h,'Position',rect,'color','none');
hPatch = findobj(h,'Type','patch');
set(hPatch,'facealpha',0.4);
xlabel('log(Array size)');
ylabel('log(Speedup)');

我尝试添加“box on”但这是相同的。

另一个问题是我想在前台显示条形图,即在网格上显示条形图。目前,如您所见,条形图是透明的网格线。我怎么能这样做?使用“Layer”或“alpha”?

2 个答案:

答案 0 :(得分:0)

尝试将其添加到代码的末尾:

ax1 = gca;
ax2 = axes('Position', get(ax1, 'Position'));
set(ax2, 'YAxisLocation', 'right', 'Color', 'none', 'XTickLabel', []);
set(ax2, 'YLim', get(ax1, 'YLim'));

答案 1 :(得分:0)

关于第二个问题:

set(hPatch,'facealpha',\alpha);
\alpha=1 %for no transparency; 
\alpha=0 %transparent