1
次のように私自身のプロットクラスを作成したいと思いますが、plt
モジュール(下記参照)を使用している間にFigure
から継承する方法が見つかりません。 Figure
から継承するか、またはtick_params
を変更します。 Figure
はクラスですので、私は継承することができますが、plt
はモジュールではありませんか?私はちょうど私の方法を見つけることを試みている初心者です...matplotlibから継承
私はそれがどのように動作するかを誰かに見せてもらえますか?
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
class custom_plot(Figure):
def __init__(self, *args, **kwargs):
#fn = os.path.join(os.path.dirname(__file__), 'custom_plot.mplstyle')
self.fig = plt
self.fig.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off') # labels along the bottom edge are off
# here id like to use a custom style sheet:
# self.fig.style.use([fn])
figtitle = kwargs.pop('figtitle', 'no title')
Figure.__init__(self, *args, **kwargs)
self.text(0.5, 0.95, figtitle, ha='center')
# Inherits but ignores the tick_params
# fig2 = plt.figure(FigureClass=custom_plot, figtitle='my title')
# ax = fig2.add_subplot(111)
# ax.plot([1, 2, 3],'b')
# No inheritance and no plotting
fig1 = custom_plot()
fig1.fig.plot([1,2,3],'w')
plt.show()