How do I show different x-axis up and down
3 ビュー (過去 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?
0 件のコメント
回答 (1 件)
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 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!