Is mathplotlib.dates.DateFormatter() deprecated since strftime() is?

Question:

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

Asked By: onthemoon01

||

Answers:

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.

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.