Adding a second x-axis to my graph, which i can scale myself

조회 수: 1 (최근 30일)
Marius Eilenberger
Marius Eilenberger 2015년 6월 23일
댓글: Marius Eilenberger 2015년 6월 25일
Hello, i am having a problem with Matlab at the moment and i hope you can help me. :) I have writen this code below to display a graph, but now i want to add another x-axis above the image, which i can scale myself. Is there any possibility to add another line like: "set(gca, 'XTick2', [bla:bla:bla]);"? Thanks in advance
EDIT: I was able to add a second x-axis, that goes from 30 to 360 in 30degree steps... but now the labels are messed up, one label is missing and the scale from the lower axis is also shown for the upper axis... can someone take a look at this, please.
The code is also the new version:
x1 = [0, 421.441, 842.882, 1264.323, 1685.764, 2107.205, 2528.646, 2950.087, 3371.528, 3792.969, 4214.41, 4635.851, 5057.29];
y1 = [55.659, 55.856, 56.081, 56.279, 56.312, 56.169, 56.038, 55.903, 55.75, 55.604, 55.512, 55.534, 55.661];
y2 = [51.231, 51.735, 52.063, 52.152, 51.632, 51.16, 51.014, 50.911, 50.721, 50.596, 50.597, 50.858, 51.242];
y3 = [50.939, 51.381, 51.644, 51.687, 51.353, 50.944, 50.829, 50.706, 50.538, 50.43, 50.412, 50.614, 50.948];
y4 = [50.023, 50.328, 50.506, 50.535, 50.352, 50.113, 50.032, 49.938, 49.801, 49.705, 49.672, 49.801, 50.03];
plot(x1,y1, 'ks-',x1,y2, 'bx--',x1,y3, 'gd-.',x1,y4, 'c.-'),
ax1 = gca;
ax1.XLim = [0, 5075];
ax1.XTick = 0:1000:5075;
ay1 = gca;
ay1.YLim = [49.5, 56.5];
ay1.YTick = 49.5:0.5:56.5;
ax2 = axes('Position',ax1.Position,'Color','none');
ax2.XLim = [0, 360];
ax2.XTick = 0:30:360;
ax2.XAxisLocation = 'top';
ax2.YTick = [];
grid off
xlabel('Time [s]')
ylabel('Temperature [°C]')
legend('A','B','C','D')

답변 (1개)

Mukul Rao
Mukul Rao 2015년 6월 24일
The link below gives an example and details to address your question.Essentially, you add a transparent axes and set the 'XAxisLocation' of this transparent axes to 'top'.
  댓글 수: 1
Marius Eilenberger
Marius Eilenberger 2015년 6월 25일
well i needed different x-axes, but i partially solved the problem, please check my edited question and see if you can help me on that. Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by