Filter löschen
Filter löschen

set y-axis to strings on plot

24 Ansichten (letzte 30 Tage)
Toke Søltoft
Toke Søltoft am 24 Jul. 2014
Beantwortet: Rodney Pratt am 28 Mär. 2019
I have these values:
x_values = [-0.6085 -0.6261 -0.6372]
y_values = [39306 39383 39460]
y_labels =
10:55:06
10:56:23
10:57:40 (strings)
Then I plot by:
plot(x_values,y_values)
Now, I want to change the y-axis labels with the strings y_labels. I do this by:
set(gca, 'YTickLabel', time_label);
The problem is that before I do this, YTickLabel consists of 9 values:
get(gca,'YTickLabel')=
3.93
3.932
3.934
3.936
3.938
3.94
3.942
3.944
3.946
and after it is of cause only the three I have in y_labels. But in the plot they are repeated 3 times:
Anyobe know how I fix so I only have these three labels on the y-axis, so they fit where the values are? Also I have to make sure that the distance between the labels are fitting the distance between the real values.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 24 Jul. 2014
x_values = [-0.6085 -0.6261 -0.6372]
y_values = [39306 39383 39460]
y_labels ={'10:55:06' '10:56:23' '10:57:40'}
plot(x_values,y_values)
set(gca, 'Ytick',y_values,'YTickLabel',y_labels);

Weitere Antworten (2)

Toke Søltoft
Toke Søltoft am 24 Jul. 2014
sweet. thank you. It works.

Rodney Pratt
Rodney Pratt am 28 Mär. 2019
Thanks for sharing this. I've just used it and it works perfectly.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by