m0_60539618 2022-11-05 19:01
浏览 229
已结题

在python中用matplotlib的imshow绘制图后再加colorbar时colorbar不能和原图在一起

在python中用matplotlib的imshow绘制图后再加colorbar时colorbar不能和原图在一起
self.left_fram = tk.Frame(self.master, borderwidth=1, relief=tk.GROOVE)
    self.left_fram.pack(side=tk.LEFT, padx=5, pady=5)
    self.right_fram = tk.Frame(self.master, borderwidth=1)
    self.right_fram.pack(side=tk.RIGHT, anchor=N, pady=5, padx=5)
    self.figure = plt.Figure(figsize=(7, 7))
    self.scatter = FigureCanvasTkAgg(self.figure, self.left_fram)
    self.scatter.get_tk_widget().pack()
    #________________________________________________
    self.net1= self.figure.add_subplot(111)
    net_info=self.net1.imshow(self.weight_matrix,cmap='pink')
    print(f"net_info: {net_info}",end='\n')
    print(f"type: {type(net_info)}", end='\n')
    plt.colorbar(net_info)
    plt.show()
MatplotlibDeprecationWarning: Starting from Matplotlib 3.6, colorbar() will steal space from the mappable's axes, rather than from the current axes, to place the colorbar. To silence this warning, explicitly pass the 'ax' argument to colorbar().

plt.colorbar(net_info)

img

网上的办法都尝试过了,还是不行,这里是一段面向对象的代码,主要的是最后几条
在tkinter中显示出绘图的结果以及colorbar
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 11月13日
    • 创建了问题 11月5日