import matplotlib.pyplot as plt
# リスト5.10.1:show()の利用
x = [1, 2, 3]
y = [3, 6, 9]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(x, y)
plt.show()
from matplotlib import rcParams
rcParams["backend"]
'module://ipykernel.pylab.backend_inline'
%matplotlib tk
rcParams['backend']
'TkAgg'
%matplotlib inline
plt.get_backend()
'module://ipykernel.pylab.backend_inline'
plt.show()
# リスト5.10.2:複数のフィギュアを出力
import matplotlib.pyplot as plt
from matplotlib._pylab_helpers import Gcf
x = [1, 2, 3]
y = [3, 6, 9]
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax1.bar(x, y)
ax2.scatter(x, y)
plt.show()
# リスト5.10.3:fig1を生成
import matplotlib.pyplot as plt
from matplotlib._pylab_helpers import Gcf
x = [1, 2, 3]
y = [3, 6, 9]
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.bar(x, y)
print("fig1: ", Gcf.get_all_fig_managers())
fig1: [<matplotlib.backend_bases.FigureManagerBase object at 0x0000023EE88540B8>]
# リスト5.10.5:fig2を生成
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.scatter(x, y)
print("fig1 & fig2: ", Gcf.get_all_fig_managers())
fig1 & fig2: [<matplotlib.backend_bases.FigureManagerBase object at 0x0000023EE88FF5F8>]
# リスト5.10.7:show()実行
plt.show()
print("after show(): ", Gcf.get_all_fig_managers())
after show(): []
# リスト5.10.9:MATLAB-styleでグラフを描画する
%matplotlib inline
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [3, 6, 9]
plt.bar(x, y)
plt.title("Sample Bar Chart")
plt.xlabel("X")
<matplotlib.text.Text at 0x23ee89d7b38>
# リスト5.10.10:OOP-styleでグラフを描画する
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [3, 6, 9]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(x, y)
ax.set_title("Sample Bar Chart")
ax.set_xlabel("X")
plt.show()