更改散点图中 x 轴的 xticks

Changing the xticks for x axis in scatterplot

我正在绘制散点图并希望将 a 轴作为比索引命名的条目。我的数据来自 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 度的 xticks 显示动物?

我想这就是你想要的:

% 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);

这给出了这个: