前提・実現したいこと
tkinterの中にmatplotlibを使ってヒストグラムを表示したい
発生している問題・エラーメッセージ
Traceback (most recent call last): File "c:\Users\yucky\Documents\Python Scripts\sample\test.py", line 23, in <module> ax2.hist(x1, bins=10, marker='o') File "C:\Users\yucky\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py", line 1361, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "C:\Users\yucky\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\axes\_axes.py", line 6911, in hist p.update(kwargs) File "C:\Users\yucky\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\artist.py", line 1062, in update raise AttributeError(f"{type(self).__name__!r} object " AttributeError: 'Rectangle' object has no property 'marker'
該当のソースコード
python
1import numpy as np 2import matplotlib.pyplot as plt 3from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 4import tkinter as tk 5 6# Prepare Data 7x1 = np.linspace(0.0, 5.0) 8y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) 9x2 = np.linspace(0.0, 3.0) 10y2 = np.cos(2 * np.pi * x2) * np.exp(-x1) 11 12# Figure instance 13fig = plt.Figure() 14 15# ax1 16ax1 = fig.add_subplot(221) 17ax1.plot(x1, y1) 18ax1.set_title('line plot') 19ax1.set_ylabel('Damped oscillation') 20 21# ax2 22ax2 = fig.add_subplot(222) 23ax2.hist(x1, bins=10, marker='o') 24ax2.set_title('Scatter plot') 25 26# ax3 27ax3 = fig.add_subplot(223) 28ax3.plot(x2, y2) 29ax3.set_ylabel('Damped oscillation') 30ax3.set_xlabel('time (s)') 31 32# ax4 33ax4 = fig.add_subplot(224) 34ax4.scatter(x2, y2, marker='o') 35ax4.set_xlabel('time (s)') 36 37 38# When windows is closed. 39 40def _destroyWindow(): 41 root.quit() 42 root.destroy() 43 44 45# Tkinter Class 46 47root = tk.Tk() 48root.withdraw() 49root.protocol('WM_DELETE_WINDOW', _destroyWindow) # When you close the tkinter window. 50 51# Canvas 52canvas = FigureCanvasTkAgg(fig, master=root) # Generate canvas instance, Embedding fig in root 53canvas.plt.hist() 54canvas.get_tk_widget().pack() 55#canvas._tkcanvas.pack() 56 57# root 58root.update() 59root.deiconify() 60root.mainloop()
補足情報(FW/ツールのバージョンなど)
windows10, python3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。