简体   繁体   中英

Matlab - right yaxis not displayed and bar over the grid

I am plotting data with a histogram. Here's the result on the following figure :

在此处输入图片说明

As you can see, the right y-axis is not displayed and I don't understand why.

My code for this plot :

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)');

I tried to add "box on" but this is the same.

Another problem is that I would like to show bars at foreground, ie over the grid. For the moment, as you can see, bars are transparent with grid lines. how could I do this ? with " Layer " or " alpha " ?

Try to add this to the end of your code:

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

For the second issue:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM