How to remove scientific notation from axes labels on log-log plot, and add thousands separator?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David Dean
el 28 de Jun. de 2022
Comentada: Walter Roberson
el 30 de Jun. de 2022
I am having difficulty making a plot with log-log axes where the axis labels are in fixed notation, not scientific notation, and commas are used as the thousands separator. After creating the plot and converting the axes to log scale, I was able to convert the axes to fixed notation using 3 methods:
1) Specifying the ticks
xtick = [1 10 100 1000];
xticks(xtick);
xticklabels(xtick);
2) xt = ax.XTick;
xt_sigfig = round(xt, 3, 'significant');
ax.XTickLabel = xt_sigfig;
3) using "compose" function
ax.XAxis.TickLabels = compose('%g', ax.XAxis.TickValues)
However, I was unable to add a thousands separator using any of those methods. For instance I would like the x tick labels to read: 1 10 100 and 1,000. And I would like the y tick labels to read: 1 10 100 1,000 10,000 and 100,000. My data and code are below using the "compose" function. Do I have to create tick labels that are strings? Any help would be greatly appreciated.
% X values
Q=[20.09 0.67 61.43 33.54 167.35 142.88 3.27 39.00 55.82 134.59 58.88 1.25 0.15 12.80 5.09 23.18 18.56 84.19 22.23 15.80 28.97 48.91 2.60 65.69 107.82]
% Y values
S=[4190 60.10 56700 39900 82000 17700 26.40 12800 135000 20100 8420 7.14 39.40 329 253 5870 4270 23400 2320 5560 9210 107000 27.40 15700 17200]
plot(Q,S,'o');
axis([0 1000 0 200000]);
set(gca,'XScale','log');
set(gca,'YScale','log');
ax=gca;
ax.XAxis.TickLabels = compose('%g', ax.XAxis.TickValues)
ax.YAxis.TickLabels = compose('%g', ax.YAxis.TickValues)
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Jun. de 2022
Editada: Walter Roberson
el 28 de Jun. de 2022
Although you can set ax.xAxis.TickLabelFormat and ax.XAxis.Exponent none of the automatic formats support thousands separator. You will need to set the tick labels.
And if you permit zoom or pan, you will need to add listeners or put in something like a ResizeFcn Callback
https://www.mathworks.com/matlabcentral/answers/8080-how-to-set-1000-separator-for-large-numbers-in-gui-matlab
5 comentarios
Walter Roberson
el 30 de Jun. de 2022
Odd...
@Stephen23 did you just happen to notice in the xtickformat information that it gives the example that %.4d format displays pi as 0003 ? That is not the same as fprintf()
fprintf('%.4d\n', pi)
but the xtickformat information appears to be correct for it
plot(rand(1,5))
xticks(pi)
xtickformat('%.4d')
Más respuestas (0)
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels 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!