You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm quite certain that this code (or similar code) worked until quite recently (I have notebooks doing this that can no longer generate their plots).
pandas 1.4.1
matplotlib 3.7.0
Basically, plotting the dataframe directly through pandas plot function and including vlines, hlines, and text causes things to break. The hlines and vlines don't show. And an attempt to show text along with the lines causes the following error to appear.
File ~/anaconda3/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:84, in RendererAgg.__init__(self, width, height, dpi)
82 self.width = width
83 self.height = height
---> 84 self._renderer = _RendererAgg(int(width), int(height), dpi)
85 self._filter_renderers = []
87 self._update_methods()
ValueError: Image size of 162825x467 pixels is too large. It must be less than 2^16 in each direction.
<Figure size 640x480 with 1 Axes>
Alternately, plotting with matplotlib directly everything seems to work fine.
import pandas as pd
import numpy as np
import dateutil
import matplotlib.pyplot as plt
# Set the start and end dates
start_date = "2022-01-01"
end_date = "2022-02-28"
# Create a DatetimeIndex at 5 minute intervals
dt_index = pd.date_range(start=start_date, end=end_date, freq="5min")
# Create a pandas dataframe with the datetime index and a random walk column
data = np.cumsum(np.random.randn(len(dt_index))) + 100
df = pd.DataFrame(data, index=dt_index, columns=["Random Walk"])
# Create a line plot using matplotlib
fig, ax = plt.subplots()
# ax.plot(df.index, df["Random Walk"]) # Plotting with matplotlib directly the text and h/vlines show up properly
df['Random Walk'].plot(ax=ax) # Plotting with pandas triggers the error
# Set the x-axis label and rotate the tick labels
ax.set_xlabel("Date")
fig.autofmt_xdate()
# Set the y-axis label
ax.set_ylabel("Random Walk")
# Set the title
ax.set_title("Random Walk Plot")
# The vlines and vlines aren't visible and the text line triggers an error IFF one of the hlines or vlines is uncommented
ax.vlines(x=dateutil.parser.parse('2022-01-20'), ymin=90, ymax=110, color='red')
ax.hlines(xmin=dateutil.parser.parse('2022-01-20'),xmax=dateutil.parser.parse('2022-01-22'), y=100, color='red')
ax.text(x=dateutil.parser.parse('2022-01-25'), y=100, s='TEST')
# Display the plot
plt.show()
The text was updated successfully, but these errors were encountered:
I'm quite certain that this code (or similar code) worked until quite recently (I have notebooks doing this that can no longer generate their plots).
pandas 1.4.1
matplotlib 3.7.0
Basically, plotting the dataframe directly through pandas plot function and including vlines, hlines, and text causes things to break. The hlines and vlines don't show. And an attempt to show text along with the lines causes the following error to appear.
Alternately, plotting with matplotlib directly everything seems to work fine.
The text was updated successfully, but these errors were encountered: