changing axis values into names

Hi,
I have the following Problem:
I created a variable that is either 1 or -1, depending on other factors, which are irrelevant for the Problem itself. Now I would like to plot the results using this code:
myData(:,1)=[726792 726793 726794 726796 726799 726800 726801 726802 ];
myData(:,2)=[1 1 1 -1 -1 1 1 -1];
plot (myData(:,1),myData(:,2))
axis([min(myData(:,1)) max(myData(:,1)) -2 2])
datetick('x','mmmyyyy')
That is woking fine, however instead of having -1 and 1 on the yaxis, I would like to have exactly this plot but on the y axis at the Point where now a 1 is Standing, i would like to write "contango" and at -1, I would like to write "backwardation". Is this somehow possible?

 採用された回答

Mischa Kim
Mischa Kim 2014 年 11 月 22 日

1 投票

Locks, add to your code
ax = gca;
ax.YTick = [-1,1];
ax.YTickLabel = {'contango','backwardation'};

5 件のコメント

Locks
Locks 2014 年 11 月 22 日
thanks a lot for your help!
I tried this:
myData(:,1)=[726792 726793 726794 726796 726799 726800 726801 726802 ];
myData(:,2)=[1 1 1 -1 -1 1 1 -1];
plot (myData(:,1),myData(:,2))
axis([min(myData(:,1)) max(myData(:,1)) -2 2])
datetick('x','mmmyyyy')
ax = gca;
ax.YTick = [-1,1];
ax.YTickLabel = {'contango','backwardation'};
Unfortunately, it does not work and I get the following warning: ??? Warning: Struct field assignment overwrites a value with class "double". See MATLAB 7.0.4 Release Notes, Assigning Nonstructure Variables As Structures Displays Warning for details.
Is there anything I need to change in addition? I am using R2012a
Star Strider
Star Strider 2014 年 11 月 22 日
Mischa’s commands are for R2014b.
For R2012a, you need to change the assignments to:
set(gca, 'YTick', [-1,1], 'YTickLabel', {'contango','backwardation'})
Locks
Locks 2014 年 11 月 22 日
perfect, exactly what I needed, thanks to both of you.
Moslem Uddin
Moslem Uddin 2019 年 1 月 4 日
I want to chane for just one point, all others will be the same . what to do ?
Steven Lord
Steven Lord 2019 年 1 月 4 日
Create a sample plot and retrieve the handle of the axes containing it.
h = plot(1:10, 1:10);
ax = ancestor(h, 'axes');
Retrieve the Y tick labels.
yL = ax.YTickLabel;
Change the retrieved labels.
yL{3} = '-999';
Update the labels in the axes.
ax.YTickLabel = yL;

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

その他の回答 (1 件)

Erenca
Erenca 2015 年 12 月 29 日

0 投票

If you wish to do it using the graphical interface, follow these steps (i am using R2015b)
  • Plot the figure.
  • On the figure window choose 'Edit' dropdown menu.
  • On the edit dropdown menu click on 'Axes properties...'
  • On the newly opened window you will see 'Ticks...' button on lower right hand side, click on it
  • Now you can replace the axis variables with whatever you want, be it number or string
best- erenca

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

質問済み:

2014 年 11 月 22 日

コメント済み:

2019 年 1 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by