Deprecationwarning in Matplotlib

Asked

Viewed 49 times

0

Hello, I am using the version "pandas==1.0.4" and in my code below has generated the following Warning:

 MatplotlibDeprecationWarning: Passing the minor parameter of set_xticks() positionally is deprecated since Matplotlib 3.2; the parameter will become keyword-only two minor releases later.

Follows my code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

bd = {'DATA': pd.date_range(start='2019-01-01',end='2020-01-01',freq='D'),
      'VALOR' :np.random.randint(1,100,size=(366))}

df2 = pd.DataFrame(bd)
df2['DATA'] = df2['DATA'].dt.strftime('%Y-%m-%d')


fig = plt.figure(figsize=(10,5))
ax = fig.add_axes([0,0,1,1])
ax.plot(df2['DATA'],df2['VALOR'])
ax.set_xticks(range(0,df2.shape[0],30))
ax.set_xticklabels(df2['DATA'].loc[::30],rotation=90)

ax2 = fig.add_axes([0.5,0.2,0.4,0.4])
ax2.plot(df2['DATA'],df2['VALOR'])
ax2.set_xticks(range(0,df2.shape[0]),110)
ax2.set_xticklabels(df2['DATA'].loc[::110],rotation=90)

plt.show()

Would anyone know the correct way to use it without receiving this Warning? Considering that in the next versions of the library will no longer work the way I have done.

Thank you!

  • A question: on the line ax2.set_xticks(range(0,df2.shape[0]),110), the correct would not be ax2.set_xticks(range(0,df2.shape[0],110)) (with the 110 inside the range)? For the second parameter of the set_xticks is a boolean value and not an integer

  • Hello, that was right, had put in the wrong place. Thank you very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.