What to do if the second axis is not positioned well?
Mostrar comentarios más antiguos
Hi,
I am trying to add second x and y axis on a plot to show different units and values. Below is the code but it sounds like it doesn't work properly as the second axes are not located properly (can be seen on attached jpg file ). I figured it out that the problem source is the first axis x and y labels as it works when I remove them. How can I fix the problem? Thanks
xlabel('()');
ylabel('Flow');
haxes1 = gca; % handle to axes
set(haxes1,'XColor','k','YColor','k')
haxes1_pos = get(haxes1,'Position'); % store position of first axes
haxes2 = axes('Position',haxes1_pos,...
'YLim',[y_min y_max],...
'XLim',[x_min x_max],...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
set(gca, 'YScale', 'log');
set(gca, 'XScale', 'log');
xlabel('d(mm)','VerticalAlignment','bottom');
ylabel('FLO','VerticalAlignment','cap');
print -djpeg -r300 chart.jpg
print -dpsc chart.eps
4 comentarios
I'd start with
hA1=axes;
instead of label, but guess it really doesn't make much difference other than I don't like the implicit creation just as a matter of style.
I didn't have any trouble with missing areas altho I did have to add
set(haxes2,'ytick',logspace(-4,4,5))
to get the labels to show on the RH axes. I'd also only use gca to retrieve the handle of the desired axes the first time and then still only if you insist in the implicit creation; otherwise always use the explicit handle in any set/get call or in [x|y]lim, etc.,to ensure you're addressing the axes desired. It's quite easy to insert some other line or make some other interaction and all of a sudden switch focus from where it's intended and gca will always return the present irregardless.
Very Determined
el 1 de Jul. de 2015
dpb
el 1 de Jul. de 2015
I don't see that...I ran your code and with the exception of the labels not matching ticks looked fine.
Very Determined
el 2 de Jul. de 2015
Editada: Very Determined
el 2 de Jul. de 2015
Respuestas (0)
Categorías
Más información sobre Axis Labels en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!