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

2 ビュー (過去 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 Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by