我无法理解如何刷新FigureCanvasWxAgg实例.这是一个例子:
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.NewId(), "Main")
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.figure = Figure(figsize=(1,2))
self.axe = self.figure.add_subplot(111)
self.figurecanvas = FigureCanvas(self, -1, self.figure)
self.buttonPlot = wx.Button(self, wx.NewId(), "Plot")
self.buttonClear = wx.Button(self, wx.NewId(), "Clear")
self.sizer.Add(self.figurecanvas, proportion=1, border=5, flag=wx.ALL | wx.EXPAND)
self.sizer.Add(self.buttonPlot, proportion=0, border=2, flag=wx.ALL)
self.sizer.Add(self.buttonClear, proportion=0, border=2, flag=wx.ALL)
self.SetSizer(self.sizer)
self.figurecanvas.Bind(wx.EVT_LEFT_DCLICK, self.on_dclick)
self.buttonPlot.Bind(wx.EVT_BUTTON, self.on_button_plot)
self.buttonClear.Bind(wx.EVT_BUTTON, self.on_button_clear)
self.subframe_opened = False
def on_dclick(self, evt):
self.subframe = SubFrame(self, self.figure)
self.subframe.Show(True)
self.subframe_opened …Run Code Online (Sandbox Code Playgroud) 我尝试:
points = [...]
axe.plot([i[0] for i in points], [i[1] for i in points], linestyle='-', linewidth=10,
color='black', markeredgewidth=2, markeredgecolor='green')
Run Code Online (Sandbox Code Playgroud)
但我只是得到一个黑色轮廓.我怎样才能实现下图所示的内容?

我在灰度图像上使用imshow函数interpolation='nearest'并得到一个漂亮的彩色图片,看起来它为我做了某种颜色分割,那到底是什么?
我也希望得到类似的东西用于图像处理,那里的numpy数组interpolate('nearest')有什么功能吗?
编辑:请纠正我,如果我错了,它看起来像是简单的像素聚类(聚类是相应颜色图的颜色)和"最近"这个词说它采用最近的颜色图颜色(可能在RGB空间中)决定像素属于哪个群集.
我有FigureCanvasWxAgg一个图表显示在框架上的实例.如果用户点击画布,FigureCanvasWxAgg则会显示另一个包含相同图形的新框架.到现在为止,关闭新帧会导致破坏图中的C++部分,使其无法用于第一帧.
我怎么能保存这个数字?复制模块中的Python深层复制在这种情况下不起作用.
提前致谢.
我有一个python的点列表(x/y坐标):
[(200, 245), (344, 248), (125, 34), ...]
Run Code Online (Sandbox Code Playgroud)
它代表2d平面上的轮廓.我想使用一些numpy/scipy算法进行平滑,插值等.它们通常需要numpy数组作为输入.例如scipy.ndimage.interpolation.zoom.
从我的积分列表中获取正确的numpy数组的最简单方法是什么?
编辑:我在我的问题中添加了"图像"这个词,希望现在很清楚,我真的很抱歉,如果它有点误导.我的意思的例子(指向二进制图像数组).
输入:
[(0, 0), (2, 0), (2, 1)]
Run Code Online (Sandbox Code Playgroud)
输出:
[[0, 0, 1],
[1, 0, 1]]
Run Code Online (Sandbox Code Playgroud)
在这里舍入接受的答案是工作样本:
import numpy as np
coordinates = [(0, 0), (2, 0), (2, 1)]
x, y = [i[0] for i in coordinates], [i[1] for i in coordinates]
max_x, max_y = max(x), max(y)
image = np.zeros((max_y + 1, max_x + 1))
for i in range(len(coordinates)):
image[max_y - y[i], x[i]] = 1
Run Code Online (Sandbox Code Playgroud)