【问题标题】:splitting the y axis into a linear and logarithmic scale matlab将y轴分成线性和对数刻度matlab
【发布时间】:2015-07-16 18:14:37
【问题描述】:

我想在绘制图形时将 y 轴拆分为线性和对数刻度部分。例如,1-30 为线性刻度,30-100 为对数刻度。有什么办法吗?谢谢

【问题讨论】:

    标签: matlab plot figure


    【解决方案1】:

    我不知道是否有直接的方法。但是,您可以手动加入两个区域(线性和对数)。见附件代码:

    clc; clear;
    
    x = 1:100; % Values to plot
    
    xorg = 0:10:100; % Ticks on the Y-axis
    xticks = xorg; % Final tick location
    
    x1 = log10(30);  % start of logarithmic scale
    x2 = log10(100); % end of logarithmic scale
    
    dx = (x2-x1)*60; % 60 here is an arbitrary scaling factor
    
    scale = @(x)(log10(x)-x1)/(x2-x1)*dx+30; % Scaling from lin to log
    
    x(x>30) = scale(x(x>30)); % Apply scaling to plotting values
    xticks(xticks>30) = scale(xticks(xticks>30)); % Apply scaling to Y ticks
    
    plot(x);
    ylim([0 max(xticks)]);
    set(gca,'YTick',xticks,'YTickLabel',xorg); % Update the ticks
    

    这会产生如下图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多