How do I show different x-axis up and down

1 次查看(过去 30 天)
I'm am plotting the energy as a function of volume for a system and I want to show the volume on the x-axis down and the corresponding sidelength (i.e. the cubic root of the volume) on a similar x-axis top. The problem is that the cubic root produces a long series of decimals and I only want the ticks at the top x-axis in integer values of the side length, which is not equal to integer numbers for the volume. I.e. I don't want the ticks top and down to be at the same positions. So far I've come up with this:
plot(V, E), hold on L = V.^(1/3) axes('YAxisLocation','right','XAxisLocation','top','color','none') set(gca,'XTickLabel',L,'YTickLabel',[])
Any idea on how I might set the 'XTick' property on the top x-axis in such a way that the ticks coinside with integer values of L?

回答(1 个)

Star Strider
Star Strider 2015-2-26
Set the 'XTickLabel' values specifically:
V = logspace(1,3,5); % Create Data
L = V.^(1/3);
xlbl = strsplit(sprintf('%.0f\n', L), '\n');
xlbl = xlbl(1:end-1);
then:
set(gca,'XTickLabel',xlbl,'YTickLabel',[])
  2 个评论
Erik
Erik 2015-2-26
Yes, that is a possibility, but that way I simply cut away the decimals, not shift the position of the tick to where L is an integer (and that is a quite noticable distance away).
Star Strider
Star Strider 2015-2-26
I don’t know what ‘E’ is supposed to be, so I got creative.
In that event, define the 'XTick' positions as well, and round the ‘L’ values first:
V = logspace(1,3,5); % Create Data
E = V.^2;
L = V.^(1/3);
RL = round(L);
xlbl = strsplit(sprintf('%.0f\n', RL), '\n');
xlbl = xlbl(1:end-1);
plot(V, E)
set(gca, 'YAxisLocation','right','XAxisLocation','top','color','none')
set(gca,'XTick',RL.^3,'XTickLabel',xlbl,'YTickLabel',[])
You will probably have to experiment to get the result you want.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by