【问题标题】:In Python Spyder interactive plotting. How do I link plots so that when I zoom in on a plot it zooms in on the rest在 Python Spyder 中交互式绘图。如何链接绘图,以便在放大绘图时放大其余部分
【发布时间】:2017-02-14 13:01:10
【问题描述】:

在 Python Spyder 中交互式绘图。如何链接图,以便当我放大一个图中的一个图时,它将同一图和不同图上的所有其他图缩放到相同的比例?它们都是相对于时间绘制的,即毫秒。

这是我当前仍在编写中的代码示例。 (我知道我在绘制相同的东西两次,我只是在测试一些东西。)

import numpy as np
import matplotlib.pyplot as plt


data = np.loadtxt('data'.csv', delimiter=',', skiprows=1)


# This uses array slicing/indexing to cut the correct columns into variables.
mSec = data[:,0]
Airspeed = data[:,10]
AS_Cmd = data[:,25]
airspeed = data[:,3]

plt.rc('xtick', labelsize=15) #increase xaxis tick size
plt.rc('ytick', labelsize=15) #increase yaxis tick size

# Create a figure figsize = ()
fig1 = plt.figure(figsize= (20,20))
ax = fig1.add_subplot(211)

ax.plot(mSec, Airspeed, label='Ground speed [m/s]', color = 'r')
ax.plot(mSec, AS_Cmd, label='AS_Cmd')
plt.legend(loc='best',prop={'size':13})
ax.set_ylim([-10,40])

ax1 = fig1.add_subplot(212)

ax1.plot(mSec, Airspeed, label='Ground speed [m/s]', color = 'r')
ax1.plot(mSec, AS_Cmd, label='AS_Cmd[m/s]')
# Show the legend
plt.legend(loc='lower left',prop={'size':8})
fig1.savefig('trans2.png', dpi=(200), bbox_inches='tight') #borderless on save

【问题讨论】:

  • 你看过散景吗?它已经为这样的事情内置了功能。

标签: python matplotlib spyder


【解决方案1】:

sharexsharey 是你的朋友。 最小的例子:

import numpy as np
import matplotlib.pyplot as plt

fig1, (ax1, ax2) = plt.subplots(1,2,sharex=True, sharey=True)
ax1.plot(np.random.rand(10))
ax2.plot(np.random.rand(11))

fig2 = plt.figure()
ax3 = fig2.add_axes([0.1, 0.1, 0.8, 0.8], sharex=ax1, sharey=ax1)
ax3.plot(np.random.rand(12))

【讨论】:

  • 没问题,我很高兴。下一次,试着提供一个更简单的例子——让那些试图帮助的人的生活更轻松。 ;-)
猜你喜欢
  • 1970-01-01
  • 2018-03-13
  • 2017-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-11
  • 2021-03-08
  • 1970-01-01
相关资源
最近更新 更多