Can my x-axis have varying scales for certain ranges of values?

5 次查看(过去 30 天)
Is it possible to scale my x-axis so the intervals are spread further apart from each other for more time-sensitive data and closer together for the data that spans across a larger time period?
For example, I would like the distance between the x-ticks to be relatively small from 60- to 180-seconds. Conversely, I would like the gaps to be significantly wider from 180-seconds to 200-seconds so the plot is less crowded.

采纳的回答

Walter Roberson
Walter Roberson 2021-12-2
Is it possible to scale my x-axis so the intervals are spread further apart from each other for more time-sensitive data and closer together for the data that spans across a larger time period?
No, it is not.
  • you could create several piecewise linear (or log) axes beside each other, and split the drawing up between them.
  • you could transform your original x data in a non-linear way, and tell xticklabels to lie about what values are there, and ignore the problems you are creating for zoom or data cursors
  • you could transform your original x data in a non-linear way, and tell xticklabels to lie about what values are there, and go through a bunch of trouble to get zoom and data cursors to act sensibly
  • you could create a subplot or inset graph that focused on the area of greatest interest

更多回答(2 个)

Chunru
Chunru 2021-12-2
Yes. You can change the tick locations:
t = 1:200;
x = sinc(2*pi*.125*t);
plot(t, x);
set(gca, 'XTick', [0:20:60 70:10:100 125:25:200])
  2 个评论
Joseph Bail
Joseph Bail 2021-12-2
Yes, but the scale is still uniform across the x-axis correct? In your example, only the labels are located at locations that are not uniform.
Chunru
Chunru 2021-12-2
You can change the tick location any way you want. The above is just an example.

请先登录,再进行评论。


the cyclist
the cyclist 2021-12-2
编辑:the cyclist 2021-12-2
Here is a simple example:
x = 1:10;
y = 2*x;
figure
plot(x,y)
xtick_loc = [0:0.5:2 3:2:7 8:0.5:10];
set(gca,'XTick',xtick_loc)
  1 个评论
Joseph Bail
Joseph Bail 2021-12-2
Perhaps I was not all that clear with my question. I am trying to scale the data differently along my x-axis. The x-axis still has a uniform scale in your example despite the ticks occurring at different locations.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by