MATLAB Answers

0

changing axis values into names

Locks 님이 질문을 제출함. 22 Nov 2014
최근 활동 Steven Lord 님이 댓글을 추가함. 4 Jan 2019
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?

  댓글 수: 0

로그인 to comment.

제품

답변 수: 2

Mischa Kim 님의 답변 22 Nov 2014
 채택된 답변

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

  댓글 수: 5

표시 이전 댓글 수: 2
perfect, exactly what I needed, thanks to both of you.
I want to chane for just one point, all others will be the same . what to do ?
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;

로그인 to comment.


Erenca 님의 답변 29 Dec 2015

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

  댓글 수: 0

로그인 to comment.



Translated by