python - 在python的散点图中根据单击的艺术家更改参数
问题描述
我在python中有一个带有选项的散点图picker=True
现在我想根据我选择的点打开另一个带有参数的 python 脚本。
我确实有一个工作活动
self.fig.canvas.mpl_connect('pick_event', self.onpick)
def onpick(self, event):
artist = event.artist
print("Hello")
...
# The scatter plot is created with
plt.scatter(data[:, 0], data[:, 1], cmap=cmap, c=data[:, 2], s=100, picker=True)
总是当我点击一个散点 python 打印Hello
。
现在我想为每个艺术家添加一个简单的信息(例如他们被创建为的顺序int
),所以当我点击它时,我可以访问这些信息并将它用作我想要在点击时打开的 python 脚本的参数.
另一个(更糟糕的)想法是,获取该艺术家在我的情节中的位置,然后根据该艺术家的位置计算我的参数。
可悲的是,如果其中一个想法是可能的,我找不到任何信息。我在https://matplotlib.org/2.0.0/users/artists.html发现艺术家有一个 x 和一个 y 值,但我无法访问它。
有什么建议么?
解决方案
您可以尝试扩展类似
import matplotlib.pyplot as plt
def onpick(event):
artist = event.artist
for scatter_plot in scatter_plots:
if artist is scatter_plot.plot:
print(scatter_plot.order)
class MyScatterPlot():
def __init__(self, order):
self.order = order
self.plot = None
fig, ax = plt.subplots()
scatter_plot1 = MyScatterPlot("first")
scatter_plot2 = MyScatterPlot("second")
scatter_plot1.plot = ax.scatter([1,1,1],[1,2,3], picker=True)
scatter_plot2.plot = ax.scatter([3,3,3],[1,2,3], picker=True)
scatter_plots = [scatter_plot1, scatter_plot2]
fig.canvas.mpl_connect('pick_event', onpick)
fig.show()
这个想法是基于这样一个事实,即您可以将您选择的对象与函数artist
返回的对象进行比较。scatter
推荐阅读
- docker - 通过 NodePort 导出服务
- r - 使用 R 使用时间和时间表之间的差异来分析巴士延误
- c++ - 基本数据类型变量 VS 对象变量
- jquery - Google Visualization API - 格式化可过滤的双轴组合图
- android-room - SQLCipher 和 CWAC-SafeRoom 使我的 APK 大小加倍
- javascript - request..args.get 什么都不存储
- paypal - PayPal Pro 托管解决方案 Iframe 响应式 CSS
- module - use 关键字中的有效路径根是什么?
- java - 在睡眠时间为 1000 毫秒的 while 循环中运行两个线程时,出现错误“无法创建新的本机线程”
- ruby-on-rails-3 - 带有复选框的服务器端处理的数据表(Rails)