python中水平方向的物理拉伸图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20398920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:19:49  来源:igfitidea点击:

physically stretch plot in horizontal direction in python

pythonmatplotlibplotstretch

提问by Bachbold

I want a simple x,y plot created with matplotlib stretched physically in x-direction.
The intention is to get a result were it is easier for me to detect features in the signal.

我想要一个简单的 x,y 图,用 matplotlib 创建,在 x 方向上物理拉伸。
目的是获得结果,因为我更容易检测信号中的特征。

So I don't want to change any scales or values or limits. Just change the distance between two gridpoint in my output file...

所以我不想改变任何尺度、值或限制。只需更改输出文件中两个网格点之间的距离...

I want to do that on four subplots which should have the same size afterwards.

我想在四个子图上这样做,之后应该具有相同的大小。

Thanks in advance... I tried for hours now and I think one of you could probably help me...

提前致谢...我现在尝试了几个小时,我想你们中的一个人可能会帮助我...

David Zwicker already solved my problem in this special case, thanks a lot for that, but in general... If I plot 2 subplots like in this code:

David Zwicker 已经在这个特殊情况下解决了我的问题,非常感谢,但总的来说......如果我在这段代码中绘制 2 个子图:

fig = plt.figure()

ax1 = fig.add_subplot(1,2,1)

plot(u_av,z)

ax2 = fig.add_subplot(1,2,2)

plot(pgrd_av,z)

clf()

and want to stretch only one of them. What can I do?

并且只想拉伸其中之一。我能做什么?

采纳答案by jmz

You can directly add axes to the canvas at an arbitrary position with plt.axes(). For instance:

您可以使用 将轴直接添加到画布的任意位置plt.axes()。例如:

ax1 = plt.axes([0, 0, 3, 0.5])
ax2 = plt.axes([0, 0.6, 1, 1])

Arbitrary axes

任意轴

回答by David Zwicker

You can change the figure size by using plt.figure(figsize=(20,5)). See the documentation of the figure command.

您可以使用 更改图形大小plt.figure(figsize=(20,5))。请参阅figure 命令文档

回答by Jyotirmay

I know, this is a bit out of the context. But if someone is looking for a solution while using pandas plot which internally uses matplotlib. Here is the solution.

我知道,这有点脱离上下文。但是,如果有人在使用内部使用 matplotlib 的 Pandas 绘图时正在寻找解决方案。这是解决方案。

df.plot('col_x', 'col_y', title='stretched_plot', figsize=(20, 1))

enter image description here

在此处输入图片说明