0
        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:

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:

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 ?

Vishal Naik
  • 134
  • 12
  • Does this answer your question? [Matplotlib: Adding an axes using the same arguments as a previous axes](https://stackoverflow.com/questions/46933824/matplotlib-adding-an-axes-using-the-same-arguments-as-a-previous-axes) – runDOSrun Sep 19 '20 at 13:03
  • No, I am unable to get any plots – Vishal Naik Sep 19 '20 at 13:04

1 Answers1

1

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":

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. 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.

runDOSrun
  • 10,359
  • 7
  • 47
  • 57