【问题标题】:Changing the xticks for x axis in scatterplot更改散点图中 x 轴的 xticks
【发布时间】:2016-09-02 08:59:37
【问题描述】:

我正在绘制一个散点图,并希望将 a 轴作为条目命名为 index。我的数据来自 R 中的 MASS,看起来像这样

animals={'Mountain beaver';'Cow';'Grey wolf';'Goat';'Guinea pig';'Dipliodocus';'Asian elephant';'Donkey';'Horse';'Potar monkey';'Cat';'Giraffe';'Gorilla';'Human';'African elephant';'Triceratops';'Rhesus monkey';'Kangaroo';'Golden hamster';'Mouse';'Rabbit';'Sheep';'Jaguar';'Chimpanzee';'Rat';'Brachiosaurus';'Mole';'Pig'};

body=[1.35  465 36.33   27.66   1.04    11700   2547    187.1   521 10  3.3 529 207 62  6654    9400    6.8 35  0.12    0.023   2.5 55.5    100 52.16   0.28    87000   0.122   192];

brain=[8.1  423 119.5   115 5.5 50  4603    419 655 115 25.6    680 406 1320    5712    70  179 56  1   0.4 12.1    175 157 440 1.9 154.5   3   180];

% Plot
x=1:length(body);
scatter(x,body,'filled','d') 
hold
scatter(x,brain,'filled') 
legend('body', 'brain','location','east');

如何修改程序,以便我的散点图以 45 度角显示动物?

【问题讨论】:

    标签: matlab scatter-plot


    【解决方案1】:

    我想这就是你想要的:

    % add these lines at the end of your code
    set(gca,'XTickLabel',animals)
    set(gca,'XTick',1:numel(animals));
    xlim([0 numel(animals)+1]);
    set(gca, 'XTickLabelRotation', 45);
    

    这给出了这个:

    【讨论】:

    • 谢谢。完美运行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 2021-11-01
    相关资源
    最近更新 更多