我想知道是否有功能可以帮助我更改已经存在的图形的颜色图(实际上是FigureCanvasTkAgg,它基本上继承了大多数Figure方法和功能),我几乎没有GUI,上面有Frame和FigureCanvasTkAgg对象。我想更改(例如使用按钮)此图的颜色映射。我创建了这样的按钮(RadioButton self.cmap)和回调:
def change_cmap(self):
plt.set_cmap(self.cmap.get())
self.canvas.draw () ## method (like show()) which draw figure
这实际上可行,但是当我将子图处理为数字时,此回调仅更改最后一个子图的cmap。有什么想法如何处理吗?为什么draw()方法不更新整个图形,而仅更新最后一个子图?
创建子图的过程(需要转换为面向对象的方法)
axes = [] # list of axes objects
fig,ax = plt.subplots ( figsize = (15,10) )
ax = fig.add_subplot ( 311 )
fig.axes[0].plot( offset[:max] , 'k' )
axes.append(ax)
ax = fig.add_subplot ( 312 )
fig.axes[1].plot ( cdp[:max] , 'b' )
axes.append(ax)
ax = plt.subplot ( 313 )
fig.axes[2].imshow( seg[: , :max] , aspect = 'auto' , cmap = cmap)
axes.append(ax)
for i in axes:
i.set_cmap('seismic) ### This raise 'AxesSubplot' object has no attribute 'set_cmap' error :(
您正在使用plt.xxxx()
作用在当前轴上的pyplot函数(有关更多详细信息,请参见https://matplotlib.org/3.2.1/tutorials/introductory/lifecycle.html)。
当有多个轴时,强烈建议您使用面向对象的方法。本质上,您将不得不遍历您的支持,并im.set_cmap(...)
在其中调用im是对所返回图像的引用imshow()
。
self.ims = []
#create subplots:
fig, axs = plt.subplots(3,1,figsize = (15,10))
axs[0].plot( offset[:max] , 'k' )
axs[1].plot ( cdp[:max] , 'b' )
im = axs[2].imshow( seg[: , :max] , aspect = 'auto' , cmap = cmap)
self.ims.append(im)
def change_cmap(self):
for im in self.ims:
im.set_cmap(self.cmap.get())
self.canvas.draw () ## method (like show()) which draw figure
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句