Azzera filtri
Azzera filtri

Changing values of axis

6 visualizzazioni (ultimi 30 giorni)
Alexander Engman
Alexander Engman il 18 Mag 2018
Commentato: Alexander Engman il 21 Mag 2018
Hi!
I have a plot such as in the attached image. As you can see, the y-axis values range from 1E-7 - 10E-7. I would like to rescale it so that it ranges from simply 0.1-1. How would I do that?
Thanks in advance.
Alexander

Risposta accettata

Sandro Lecci
Sandro Lecci il 18 Mag 2018
Hi Alexander,
To change the limits of the axis do the following:
set(gca, 'YLim', [0.1,1])
However, your data will not be displayed as they are smaller than the lower limit (0.1). You would want to multiply them by a specific factor, such as *1E6 ?
Best, Sandro
  1 Commento
Alexander Engman
Alexander Engman il 21 Mag 2018
Hi Sandro,
thank you for your answer. The problem is that the plot is a contour plot, meaning my function depends on both the variable on the y-axis and the x-axis. So the values on the y-axis are predetermined and MATLAB formats the axis values automatically. I understand the point behind the formatting but for my purpose it is not ideal. Any ideas?

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 21 Mag 2018
You can set the axes YTickLabels to whatever you want, including to strings that have nothing to do with the actual Y values.
You can use mat2gray() or the new rescale() to change the y values to your desired range before you plot them.
  1 Commento
Alexander Engman
Alexander Engman il 21 Mag 2018
Thank you Walter. I found an easy solution. I though that multiplying the axis in the contour plot would change the plot values, but of course it doesnt. I just multiplied the y-axis values by 10E6 and then plotted on the appropriate scale.
[C,h]=contour(Vfvecq, rvecq*10^6, OPTq,'Color','k');

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by