Matlab scatter plot set x-axis and y-axis

I have an array with two columns (date, value) to plot
What I want is to set the labels to show the values on y-axis (e.g 918.5345).
ALso, the x-axis to be just the values on (date) ... (e.g 2002 2003 2004 ...) and not 2002.5 2003.5
I use Matlab R2016a
Screenshot 2019-02-13 at 21.40.34.png
date = [2002 2003 2004 2005 ....] %sometimes 2003 2005 2006 2009 and so on%
value = [918.5345 918.5361 918.5354 ....]
When I plot a scatter as follows:
subplot(3,1,1);
hold on;
scatter(date,value,'+');
grid on
xlabel('Time')
ylabel('Y(m)')
hold off

回答 (1 件)

Nathan Jessurun
Nathan Jessurun 2019 年 2 月 13 日

1 投票

Take a look at the xticks function:
plot(1:10)
% Only show 1, 5, 10 on the x axis
xticks([1 5 10])
What do you mean by you want to show labels on the y axis? Are you asking for this:
xData = 1:4;
yData = 1:5:20;
scatter(xData,yData);
xticks(xData);
yticks(yData);

3 件のコメント

Mohammed Hammad
Mohammed Hammad 2019 年 2 月 14 日
編集済み: Mohammed Hammad 2019 年 2 月 14 日
I mean to show labels on the axes as follows:
on X-axis:
the dates (2002 2003 2004 2005) ( without 2002.5, 2003.5)
On Y-Axis:
format of (918.5345 918.5361 ....) not the interval from -4 to 0
Please note that in Matlab version R2016a that I have, the xticks, yticks are not working.
Nathan Jessurun
Nathan Jessurun 2019 年 2 月 14 日
I see that xticks was added in 2016b.
In your case, you can try
xData = 5:10;
yData = 800:200:1800;
scatter(xData,yData);
% Get current axis
fig = gcf;
ax = fig.Children;
ax.XTick = xData;
ax.YTick = yData;
Mohammed Hammad
Mohammed Hammad 2019 年 2 月 14 日
Thanks a lot , it looks more better now.

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

カテゴリ

製品

リリース

R2016a

質問済み:

2019 年 2 月 13 日

コメント済み:

2019 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by