How do I show different x-axis up and down

1 visualización (últimos 30 días)
Erik
Erik el 26 de Feb. de 2015
Comentada: Star Strider el 26 de Feb. de 2015
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?

Respuestas (1)

Star Strider
Star Strider el 26 de Feb. de 2015
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 comentarios
Erik
Erik el 26 de Feb. de 2015
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 el 26 de Feb. de 2015
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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by