Move the position of y-axis exponent (R2017a)
Afficher commentaires plus anciens
I have data plotted on my y-axis with values in the order of 10^10, and I'm using a reverse axis. I want to keep the scientific notation exponent on the axis on the top of my plot as it interfers with the x-axis labels otherwise. How do I do it? I could only find answers for earlier versions.
Thanks!
1 commentaire
Réponses (1)
Jaime López
le 15 Sep 2020
Modifié(e) : Jaime López
le 15 Sep 2020
As far as I know, there is no direct way to interact with the exponent of any axis.
A workaround, with the drawback that is has to be done by hand, is to put the exponent wherever you want writting it as text, using annotation():
If so, first you have to make the old one dissapear, which you can do by setting the YTickLabelMode property to 'manual'. For example:
AxisObject = gca; % Asigns the axis to a variable
ExponentToBeUsedLater = AxisObject.YAxis.Exponent; % Stores the exponent for later, since it is going to be erased
AxisObject.YTickLabelMode = 'manual'; %Set the Y tick labels to manual, which kind of deletes the exponent
*Remember that, if you set the YTickLabelMode to manual, the tick labels (the little numbers along the axis) will no longer change automatically if you resize your figure, so you have to that first.
Once the old exponent is erased, you can manually add the new one
annotation('textbox', WhereverYouWantYourExponent, 'String', ['x 10^', num2str(ExponentToBeUsedLater)], 'EdgeColor', 'none');
You can find additional options for annotation() in the Matlab documentation
5 commentaires
Adam Danz
le 15 Sep 2020
You can interact with the exponent in terms of reformatting it
I'm using r2019b right now and the exponent does not switch sides when the ydir is reversed. When the xaxis location is switched to top, the exponent notation along the y axis goes to the bottom. So this no longer seems to be a problem.
@Jaime López, I'd be interested if you've found a way to recreated this problem. I tried but couldn't.
Jaime López
le 16 Sep 2020
You mean a full example of hot to move the exponent?
Adam Danz
le 16 Sep 2020
No, I mean an example that shows the problem of the exponent overlapping with the x tick labels. I tried to make this happen in r2019b and couldn't.
Jaime López
le 16 Sep 2020
I can't do it either. I didn't have that exact problem, but a related one that I exposed in the forums:
https://www.mathworks.com/matlabcentral/answers/529323-axis-exponent-not-displaying-when-changing-ticklabels?s_tid=prof_contriblnk
Adam Danz
le 16 Sep 2020
I see.
This answer shows a nice approach of applying a listeners to reassign tick labels when the axis limits change.
Catégories
En savoir plus sur Axis Labels dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!