2

As a newbie in coding, I don't understand fully if I can use matplotlib.dates.DateFormatter() without reservation, knowing that the function rely on strftime() which is deprecated.

I was trying to fix a tick issue (how to change date format for xlabel ticks) and ran into this effective solution

This solution rely on matplotlib.dates.DateFormatter().
This is my code using this function:

import pandas as pd  
import matplotlib.pyplot as plt  
import matplotlib.dates as mdates  

fig, ax = plt.subplots()  
plt.plot(df.loc[:, "LAST_PRICE"])  
hourFmt = mdates.DateFormatter('%H')  
ax.xaxis.set_major_formatter(hourFmt) 
plt.show()   

This solution works fine.

The problem is that when trying to understand the function, I read that strftime() is deprecated

Is it reasonable to use this function in my code, and if yes, why?
Thank you for your help

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
onthemoon01
  • 103
  • 1
  • 10

1 Answers1

2

Is it reasonable to use this function in my code, and if yes, why?

Yes it is, because it allows to format dates nicely on a matplotlib axis.

I read that strftime() is deprecated..

Indeed matplotlib.dates.DateFormatter.strftime is deprectated. But you're not using it anyways. You are using matplotlib.dates.DateFormatter and that is fully functional and will remain supported.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712