1
다음과 같이 자신의 플로팅 클래스를 만들고 싶습니다. 모듈을 사용하는 동안 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()