在曲线下添加颜色,使用 AxesSubplot 对象(matplotlib 和 tkinter)

Adding color under a curve, with AxesSubplot object (matplotlib & tkinter)

我正在使用 matplotlib 模块在 tkinter 中绘制图形 window。 我正在使用 AxesSubplot 对象来配置图形的样式。

我的问题是:如何使用此对象(AxesSubPlot 对象)在图形曲线下方绘制颜色? 这是我用来配置和绘制图形的代码:

def graph_handle(self):

    canvas = matplotlib.backends.backend_tkagg.FigureCanvasTkAgg(self.__fig, master=self.__SettingsFrame)
    canvas.show()
    canvas.get_tk_widget().pack(side=BOTTOM, fill=BOTH, expand=True)

    self.__axes = self.__fig.add_subplot(1,1,1,axisbg='#221E1E')
    self.__axes.plot([0])
    self.__axes.spines['bottom'].set_color('black')
    self.__axes.spines['top'].set_color('white')
    self.__axes.spines['left'].set_color('#221E1E')
    self.__axes.spines['right'].set_color('#221E1E')
    self.__axes.xaxis.label.set_color('#221E1E')
    self.__axes.tick_params(axis='x', colors='black')
    self.__axes.tick_params(axis='y', colors='#221E1E')

    self.__fig.gca().clear()
    self.__fig.gca().plot([0], [0])
    self.__fig.canvas.draw()

当然我在代码和其他东西中有 tkinter 设置,如果你认为它是相关的,请在评论中写下来,我会添加。

谢谢。

编辑: 到目前为止,代码提供了这张图: 我想在曲线下(曲线和下轴之间)添加颜色(抱歉画得不好,这只是一个演示):

编辑 2:

这是我在更新要绘制的数组时调用的函数(即,当我需要更新图形时,因为要绘制的数组中的值比以前多):

def update_plot(self, txnamount):

    self.__GraphPlot[0].append(self.__TransactionsCurrently)
    self.__GraphPlot[1].append(self.__WalletBalance+txnamount)

    self.__axes.fill_between(self.__GraphPlot[0], self.__GraphPlot[1], facecolor="yellow")

    self.__fig.gca().clear()
    self.__fig.gca().plot(self.__GraphPlot[0], self.__GraphPlot[1], color="white", linewidth=0.8)
    self.__fig.canvas.draw()

您需要使用 Axes.fill_betweenmatplotlib page.

上有一个很好的例子

在这种情况下,您将使用

self.__axes.fill_between(x,y, facecolor='yellow')

其中 xy 是要绘制的数组。