proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.07k stars 96 forks source link

proplot can't plot string like datetime #436

Open singledoggy opened 10 months ago

singledoggy commented 10 months ago

Description

proplot can't plot string like datetime

Steps to reproduce

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.

import pandas as pd
import numpy as np
start_date = '2023-01-01'
end_date = '2023-12-31'

dates = pd.date_range(start=start_date, end=end_date, freq='D')

data = np.random.randn(len(dates))

time_series = pd.Series(data, index=dates)

# proplot
import proplot as pplt
import matplotlib.pyplot as plt
fig, axs = pplt.subplots(ncols=1, nrows=1, figwidth=13, refaspect=4,)
time_series.plot(ax=axs)
axs.hlines(0.8, start_date, end_date)
plt.hlines(0.5, start_date, end_date)
axs.format(
    suptitle='', xlabel='xlabel', ylabel='ylabel', abc=True,
)

# %%
# matplotlib
fig, axs = plt.subplots()
time_series.plot(ax=axs)
axs.hlines(0.8, start_date, end_date)
plt.hlines(0.5, start_date, end_date)
axs.format(
    suptitle='', xlabel='xlabel', ylabel='ylabel', abc=True,
)

Expected behavior: [What you expected to happen]

image

Actual behavior: [What actually happened]

image

Equivalent steps in matplotlib

Please try to make sure this bug is related to a proplot-specific feature. If you're not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.

See the code above.

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version) here. 3.4.3 0.9.5.post360

How to quick fix

start_date = np.datetime64('2022-01-01')
end_date = np.datetime64('2023-12-31')

Proplot is capable of accepting datetime formats other than string formats. However, if it does not support accepting string inputs as datetimes, it would be advisable to raise a warning to avoid confusion among users.