[英]Adding color under a curve, with AxesSubplot object (matplotlib & tkinter)
I'm using matplotlib module in order to draw graph in tkinter window. 我正在使用matplotlib模块以便在tkinter窗口中绘制图形。 I'm using AxesSubplot object to configure the graph's style.
我正在使用AxesSubplot对象来配置图形的样式。
My question is: How do I draw color under the curve of the graph, with this object (AxesSubPlot object)? 我的问题是:如何使用该对象(AxesSubPlot对象)在图形的曲线下绘制颜色? This is the code that I use to configure and draw the graph:
这是我用来配置和绘制图形的代码:
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()
Of course I have the tkinter settings in the code and other stuff, If you think it's relevant, write this down in the comments and i'll add. 当然,我在代码和其他内容中有tkinter设置,如果您认为这是相关的,请在注释中写下来,然后添加。
Thanks. 谢谢。
Edit: So far, the code provides this graph: 编辑:到目前为止,代码提供了此图:
And I want to add color under the curve (Between the curve and the down axis)(Sorry for the bad drawing, it's just a demonstration):
我想在曲线下添加颜色(在曲线和下轴之间)(不好的绘图,这只是一个演示):
Edit2: EDIT2:
This is the function that I call whenever the array to plot is updated(ie, when I need to update the graph, because there are more values in the array to plot then before): 每当要绘制的数组更新时(即,当我需要更新图形时,因为数组中要绘制的值比以前更多),我就调用此函数:
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()
You need to use Axes.fill_between
. 您需要使用
Axes.fill_between
。 There is a nice example on the matplotlib page . matplotlib页面上有一个很好的示例。
In this case you'd use 在这种情况下,您将使用
self.__axes.fill_between(x,y, facecolor='yellow')
where x
and y
are the array to plot. 其中
x
和y
是要绘制的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.