Skip to content

Plot function breaking with vlines and hlines. #53090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aluchko opened this issue May 4, 2023 · 2 comments
Closed

Plot function breaking with vlines and hlines. #53090

aluchko opened this issue May 4, 2023 · 2 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member Visualization plotting

Comments

@aluchko
Copy link

aluchko commented May 4, 2023

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

@lithomas1 lithomas1 added Bug Visualization plotting Needs Triage Issue that has not been reviewed by a pandas team member labels May 5, 2023
@azhu-tower
Copy link
Contributor

Probably due to the same issue described in #52895 (comment)

@mroeschke
Copy link
Member

Closing as a root issue of #52895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member Visualization plotting
Projects
None yet
Development

No branches or pull requests

4 participants