[英]Unable to get plot /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning:
date high low close Central Bottom Top_Central Resistance_1 Support_1 Central_SMA Bottom_Central_SMA Top_Central_SMA
1 2010-01-05 142.45 136.00 141.85 140.100000 139.225 140.975000 NaN NaN NaN NaN NaN
2 2010-01-06 142.70 140.40 141.00 141.366667 141.550 141.183333 143.266667 138.891667 140.733333 140.3875 141.079167
3 2010-01-07 142.65 140.05 141.60 141.433333 141.350 141.516667 142.575000 140.125000 141.400000 141.4500 141.350000
4 2010-01-08 142.40 139.85 141.90 141.383333 141.125 141.641667 142.866667 140.291667 141.408333 141.2375 141.579167
5 2010-01-11 146.00 141.95 145.35 144.433333 143.975 144.891667 144.916667 141.616667 142.908333 142.5500 143.266667
Above dataframe is pivot DataFrame in my code.上面的数据框是我的代码中的枢轴数据框。
import matplotlib.dates as mdates
from matplotlib.dates import date2num
import matplotlib.pyplot as plt
Graph=pivot.copy()# Make a copy of pivot
try:
Graph.reset_index(inplace=True)
Graph['date'] = Graph['date'].apply(date2num)
except:
pass
fig= plt.figure()
ax1= fig.add_subplot(111)
ax2= fig.add_subplot(111)
ax3= fig.add_subplot(111)
ax1.xaxis_date()
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
ax2.plot(Graph.date, Graph['Resistance_1'], label='R1')
ax3.plot(Graph.date, Graph['Support_1'], label='S1')
plt.show()
When I run the above code I get the following error.当我运行上面的代码时,出现以下错误。
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning: /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning:
Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.使用与先前轴相同的参数添加轴当前会重用较早的实例。 In a future version, a new instance will always be created and returned.在未来的版本中,将始终创建并返回一个新实例。 Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.同时,通过将唯一标签传递给每个轴实例,可以抑制此警告并确保未来的行为。
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: MatplotlibDeprecationWarning: /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: MatplotlibDeprecationWarning:
Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.使用与先前轴相同的参数添加轴当前会重用较早的实例。 In a future version, a new instance will always be created and returned.在未来的版本中,将始终创建并返回一个新实例。 Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.同时,通过将唯一标签传递给每个轴实例,可以抑制此警告并确保未来的行为。
How to resolve this issue ?如何解决这个问题?
Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.使用与先前轴相同的参数添加轴当前会重用较早的实例。
The same argument that is meant here is "111":此处所指的相同参数是“111”:
ax2= fig.add_subplot(111)
ax3= fig.add_subplot(111)
The behavior is specified in the warning message: it doesn't add a new figure, it reuses the old one.该行为在警告消息中指定:它不会添加新图形,而是重用旧图形。 So you only have 1 figure even though you probably want to specify 3. I assume you need to look up the syntax of subplot and are mistaking it for something that it is not.因此,即使您可能想要指定 3,您也只有 1 个数字。我假设您需要查找 subplot 的语法,并将其误认为不是。 One correct way to use this would be:使用它的一种正确方法是:
ax1= fig.add_subplot(131)
ax2= fig.add_subplot(132)
ax2.plot(a,b)
ax3= fig.add_subplot(133)
ax3.plot(b,a)
You can also use 31X if you rather want 3 rows of images.如果您想要 3 行图像,也可以使用 31X。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.