python语言实现lassocv中的可视化显示_python – 让Lasso在matplotlib中的子图上正常工作...

我想创建一个散点图矩阵,它将由一些子图组成.我从.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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值