作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在处理一个数据集,其中包含持续时间约为 10 秒、采样时间为 0.1 秒的信号。我的目标是提取该数据的特定部分并将其保存到 python 字典中。相关部分长约4秒。
理想情况下,这就是我想做的:
绘制整个 10 秒的数据。
标记信号的相关部分,例如使用边界框。
关闭绘图窗口或按下按钮后提取边界框中的数据。
返回 1. 并获取新数据。
我看到 matplotlib 能够绘制补丁并提取补丁中的数据点。是否可以在创建绘图后(执行 plt.show() 命令后)向绘图添加补丁?
预先感谢您并致以最诚挚的问候,
曼努埃尔
最佳答案
您可以使用SpanSelector
.
你基本上只需要添加一行来保存到 the matplotlib example .
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(211)
x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))
ax.plot(x, y, '-')
ax.set_ylim(-2, 2)
ax.set_title('Press left mouse button and drag to test')
ax2 = fig.add_subplot(212)
line2, = ax2.plot(x, y, '-')
def onselect(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax))
indmax = min(len(x) - 1, indmax)
thisx = x[indmin:indmax]
thisy = y[indmin:indmax]
line2.set_data(thisx, thisy)
ax2.set_xlim(thisx[0], thisx[-1])
ax2.set_ylim(thisy.min(), thisy.max())
fig.canvas.draw_idle()
# save
np.savetxt("text.out", np.c_[thisx, thisy])
# set useblit True on gtkagg for enhanced performance
span = SpanSelector(ax, onselect, 'horizontal', useblit=True,
rectprops=dict(alpha=0.5, facecolor='red'))
plt.show()
关于python - 如何选择绘图中的区域 (Python) 并提取该区域内的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44990722/
我有数百个位置的列表,只想显示当前屏幕上这些位置的 MKPinAnnotation。屏幕从 2 英里半径内的用户当前位置开始。当然,用户可以滚动和缩放屏幕。现在,我等待 map 更新事件,然后循环遍历
我试过检查 CGRect: CGFloat imageX1 = imageView.frame.origin.x; CGFloat imageY1 = imageView.frame.origin
我是一名优秀的程序员,十分优秀!