我想创建一个散点图矩阵,它将由一些子图组成.我从.txt文件中提取了我的数据,并创建了一个形状数组(x,y,z,p1,p2,p3,p4).数组的前三列表示来自原始图像的这些数据来自的x,y,z坐标,以及最后四列(p1,p2,p3,p4)的一些其他参数.因此,在数组的每一行中,参数p1,p2,p3,p4具有相同的坐标(x,y,z).在散点图中,我想要将每个p_i(例如p1)参数可视化为对另一个p_i(例如p2,p3,p4)参数.
我想在每个子图中绘制一个感兴趣区域(ROI),突出显示每个子图中ROI中包含的点.在每个子图中,可视化不同的参数(例如,p1对p2),但是对于每个子图中的一个点,在其余子图中存在具有相同的x,y,z坐标的另一个点.我使用matplotlib示例Lasso实现了ROI的绘制.此代码实现的示例如下图所示.
我的实施出现故障.我可以在每个子图中绘制套索,但是当在特定子图中绘制套索时,点会被突出显示,该子图对应于我的代码中的LassoManager函数的第一次调用(在我的代码选择器1中).从下图中可以看出,给出了可以在不同子图中绘制的套索的初始值,但是只使用选择器1中对应的id导致代码故障,独立于我绘制的子图中投资回报率.
这是我的代码:
"""
Show how to use a lasso to select a set of points and get the indices
of the selected points. A callback is used to change the color of the
selected points
This is currently a proof-of-concept implementation (though it is
usable as is). There will be some refinement of the API.
"""
from matplotlib.widgets import Lasso
from matplotlib.colors import colorConverter
from matplotlib.collections import RegularPolyCollection
from matplotlib import path
import matplotlib.pyplot as plt
import numpy as np
class Datum(object):
colorin = colorConverter.to_rgba('red')
colorout = colorConverter.to_rgba('blue')
def __init__(self, x, y, include=False):
self.x = x
self.y = y
if include: self.color = self.colorin
else: self.color = self.colorout
class LassoManager(object):
#class for highlighting region of points within a Lasso
def __init__(self, ax, data):
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
self.Nxy = len(data)
facecolors = [d.color for d in data]
self.xys = [(d.x, d.y) for d in data]
fig = ax.figure
self.collection = RegularPolyCollection(
fig.dpi, 6, sizes=(1,),
facecolors=facecolors,
offsets = self.xys,
transOffset = ax.transData)
ax.add_collection(self.collection)
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
def callback(self, verts):
facecolors = self.collection.get_facecolors()
print "The id of this lasso