removing ticks on top and right axes

135 ビュー (過去 30 日間)
Reddy Yettapu
Reddy Yettapu 2022 年 11 月 25 日
コメント済み: Robert U 2022 年 11 月 28 日
Hello,
My plot in matlab, by default, has ticks on both left and right and top and bottom. However, I want ticks to be only on left and bottom while keeping the axes on all four sides. Is there any command to remove ticks on top and right sides of the box.
Many thanks in advance!

回答 (2 件)

Robert U
Robert U 2022 年 11 月 25 日
Hi Reddy Yettapu,
it is not possible to control the top and right axis separately. You can add the desired behavior manually with the drawback that it won't scale with the figure if you zoom out.
arg = 0:9;
data = rand(1,10);
fh = figure;
ah = axes(fh);
plot(ah,arg,data,'o-');
ah.Box = 'off';
xline(ah,ah.XLim(2))
yline(ah,ah.YLim(2))
Kind regards,
Robert
  3 件のコメント
Reddy Yettapu
Reddy Yettapu 2022 年 11 月 25 日
It is working when I run your code seperately. However, when I included it in my script file, where I am plotting multiple plots in the same graph, top and right axes are missing. Please have a look at the attached screenshot how I included your code into mine.
Thanks,
Reddy
Robert U
Robert U 2022 年 11 月 28 日
Hi Reddy Yettapu,
could you send the figure as mat-file? It does not need to contain your original data, dummy data would be fine.
The top and right axes are missing since they are switched off. The xline() and yline() commands only provide the appearance of the box. These commands need to be executed when the figure is already finished. The lines are fixed to the x- and y-values and will not scale with the graph.
Kind regards,
Robert

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


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022 年 11 月 25 日
Here is one easy solution to manipulate ticks, e.g.:
x = linspace(0,pi);
y = sin(x.^2);
plot(x,y), grid on
yticks([ ])
xticks([0 pi/3 pi/2 2*pi/3 pi])
xticklabels({'x=0','x = \pi/3', 'x=\pi/2','x = 2*\pi/3', 'x=\pi'})
  1 件のコメント
Reddy Yettapu
Reddy Yettapu 2022 年 11 月 25 日
編集済み: Reddy Yettapu 2022 年 11 月 25 日
Thanks for your answer. I want ticks to be only on left and bottom axes. However, in your plot it has ticks on top and bottom. Please let me know if you have any alternative.
Thanks,
Reddy

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by