【问题标题】:Setting y-axis labels to be in scientific notation将 y 轴标签设置为科学计数法
【发布时间】:2016-04-12 09:11:06
【问题描述】:

我现在遇到的一个问题是,当我在一个图形上绘制多个图时,其中一些是用科学计数法的 y 轴绘制的,而另一些则不是。它使情节看起来有些丑陋和不一致,例如:

我尝试了几种我在网上找到的解决方案,得到了非常奇怪的结果(它们都没有达到我想要的效果)。

我正在创建这样的子图:

for i = 1:size(clusters, 2) % for each cluster in clusters (a cell array).
    cluster = cell2mat(clusters(i)); % get the matrix stored in the element
    nRows = size(cluster,1); % number of rows in the matrix
    x = 1:nRows; % x axis (row index of matrix)
    figure(2) 
    subplot(3,2,i);
    plot(x, cluster'); % plot the graph
end
end

为什么某些子图的 y 标签是科学记数法,而其他子图不是?有没有解决的办法?此外,当我在这里时,每个集群都对应一个矩阵 - 如果是这种情况,那么 y 轴究竟代表什么?

非常感谢您的帮助。

【问题讨论】:

    标签: matlab plot subplot bigdata


    【解决方案1】:

    在您的示例中,不是格式的差异,而是不同的位数使 MATLAB 在某些图中压缩数字。

    但是,如果用科学记数法,你的意思是数字的科学格式,那么你可以很容易地实现它。看看下面的例子:

    x = 1:10000;
    y = 1000*log10(x);
    plot(x,y)
    xlab = linspace(1,10000,6);
    ylab = linspace(1,4000,6);
    set(gca,'XTick',xlab)
    set(gca,'XTickLabel',sprintf('%1.2e\n',xlab))
    set(gca,'YTick',ylab)
    set(gca,'YTickLabel',sprintf('%1.2e\n',ylab))
    

    在左侧,您可以看到 [MATLAB] 通常如何格式化绘图中的数字,而在右侧,您可以看到我的示例完成的格式化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 2020-06-26
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多