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() wich 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

Ned
  • 1,288
  • 17
  • 27
onthemoon01
  • 73
  • 1
  • 9

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
  • 289,005
  • 45
  • 571
  • 615