How to move the Yaxis exponent outside

8 visualizaciones (últimos 30 días)
Madmad
Madmad el 19 de Feb. de 2024
Comentada: Voss el 20 de Feb. de 2024
I would like to move the exponent of the Y axis that is naturally above the figure, to the outside (left side) of the figure.
See my impressive plot attached. Any suggestion (I mean with an automatic way) such as 'TickDir' 'out' for the ticks, but for the exponent x10^6 here. Cheers

Respuesta aceptada

Voss
Voss el 19 de Feb. de 2024
I don't know of a way to move that exponent label, but if you have R2023b or later, you can use the ysecondarylabel function to set its string to empty, and then create your own exponent label (using the text function) where you want.
plot(1e6:1e6:7e6)
ylim([1e6 7.5e6])
ax = gca();
ysecondarylabel(ax,'')
text(ax, ...
'String','x10^{6}', ...
'Units','normalized', ...
'Position',[0 1], ...
'HorizontalAlignment','right', ...
'VerticalAlignment','bottom')
  2 comentarios
Madmad
Madmad el 20 de Feb. de 2024
Thanks for your method, I do not have 2023 but I will keep writing using text.
Best
Voss
Voss el 20 de Feb. de 2024
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Feb. de 2024
Here is one example how to get it done:
% Sample data for plot display
x = linspace(0, 2*pi, 100);
y = 1e6 * sin(x);
%% Demo 1
figure;
plot(x, y);
yticks([0, max(y)])
yticklabels({'0', '10^6'});
ylabel('Y-axis');
title('Example Plot');
xlabel('X-axis');
%% Demo 2
figure;
plot(x, y);
yticks([min(y), 0, max(y)])
yticklabels( {'-10^6', '0', '10^6'});
ylabel('Y-axis');
title('Example Plot');
xlabel('X-axis');
  1 comentario
Madmad
Madmad el 19 de Feb. de 2024
Thanks for your answer, but this is not what I am looking for. On your second example, I would like -1 0 1 to be displayed on the y axis; with the exponent at the top. I do not want the exponent x10^6 written at each line like in your example, I need the number on the left of the figure rather than above it, like in my example.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by