How to repeat a pattern on xticks?

5 ビュー (過去 30 日間)
Wolfgang McCormack
Wolfgang McCormack 2021 年 3 月 12 日
コメント済み: Mathieu NOE 2021 年 3 月 12 日
Hi all,
I have the following for a plot. How can I make the A,B,C,D,E repeat for 100 times on the x label with the same patttern A,B,...
set(gca,'XTickLabel',{'A','B','C','D','E'})
Also, is there anyway to make it appear 90° rotated on the x axis?

採用された回答

Star Strider
Star Strider 2021 年 3 月 12 日
Try this:
x = 0:24;
y = rand(size(x));
figure
plot(x, y)
set(gca, 'XTick',x, 'XTickLabel',{'A','B','C','D','E'}, 'XTickLabelRotation',90)
I restricted the x-axis to go from 0 to 24 to make it readable. To use 100 values for ‘x’ may require a smaller font as well, although this could affect the font size for both axes. Another option is to increase the figure width using the 'Position' property. See the documentation section on Position and Size for information on that.
  2 件のコメント
Wolfgang McCormack
Wolfgang McCormack 2021 年 3 月 12 日
@Star Strider @Mathieu NOE Thank you guys both. So another quick question, when my plot is created it's messed up until I make it full size. so is there a way to automatically save as the screen size? maybe using size? thx (I did not name my plot because it's multiple for loops with if statements so I cannot say like PlotX then size of PlotX, it's just a flow of plots :D using the command directly without assigning it to anything)
Star Strider
Star Strider 2021 年 3 月 12 日
It depends on the result you want. To change the entire figure size, use the OuterPosition property.
Example —
x = 0:99;
y = rand(size(x));
figure
plot(x, y)
set(gca, 'XTick',x, 'XTickLabel',{'A','B','C','D','E'}, 'XTickLabelRotation',90)
opos = get(gcf,'OuterPosition');
set(gcf, 'OuterPosition',opos+[-750 -500 1050 500])
Experiment with the vector in the last line to get different results. Use the Position property (that apparently does not have a direct link) to change the size of the drawable area.

サインインしてコメントする。

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 3 月 12 日
hello
this is an example for 20 repetition of the 5 letters pattern + 90° rotated
plot(1:100,randn(1,100));
set(gca,'XTick',(1:100),'XTickLabel',repmat({'A','B','C','D','E'},1, 20))
xtickangle(90)
  2 件のコメント
Wolfgang McCormack
Wolfgang McCormack 2021 年 3 月 12 日
編集済み: Wolfgang McCormack 2021 年 3 月 12 日
this one works perfectly as well but I could just pick one so I picked the one who commented first. Thank you Mathieu!
Mathieu NOE
Mathieu NOE 2021 年 3 月 12 日
that's life ! it's hard to beat a MVP !! I have to admit I still have to learn a few things before I'm up to the task

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by