Skip to content

[Bug]: pixeled dotted lines with no readability #30042

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

Open
PonySubway opened this issue May 12, 2025 · 3 comments
Open

[Bug]: pixeled dotted lines with no readability #30042

PonySubway opened this issue May 12, 2025 · 3 comments
Labels
status: needs clarification Issues that need more information to resolve.

Comments

@PonySubway
Copy link

Bug summary

Image
I run into issues in using mayplotlib and only yields pixeled dotted lines with no readability.
Anyone knows how to fix it?

Code for reproduction

import matplotlib.pyplot as plt

load = [
    65.0, 65.0, 65.0, 65.0,
    62.0, 62.0, 62.0, 62.0,
    59.0, 59.0, 59.0, 59.0,
    69.0, 69.0, 69.0, 69.0,
    70.0, 70.0, 70.0, 70.0,
    61.0, 61.0, 61.0, 61.0,
    70.0, 70.0, 70.0, 70.0,
    82.0, 82.0, 82.0, 82.0,
    92.0, 92.0, 92.0, 92.0,
    97.0, 97.0, 97.0, 97.0,
    98.0, 98.0, 98.0, 98.0,
    96.0, 96.0, 96.0, 96.0,
    96.0, 96.0, 96.0, 96.0,
    94.0, 94.0, 94.0, 94.0,
    93.0, 93.0, 93.0, 93.0,
    95.0, 95.0, 95.0, 95.0,
    96.0, 96.0, 96.0, 96.0,
    96.0, 96.0, 96.0, 96.0,
    95.0, 95.0, 95.0, 95.0,
    93.0, 93.0, 93.0, 93.0,
    89.0, 89.0, 89.0, 89.0,
    80.0, 80.0, 80.0, 80.0,
    68.0, 68.0, 68.0, 68.0
]

t    = np.arange(0, 23, 0.25)     # 15-min resolution in hours


fig, ax = plt.subplots(figsize=(12, 4), dpi=140)  # bigger & sharper
ax.step(t, load, where="post", lw=2)              # solid 2-pt staircase
ax.set_xlim(0, 24)
ax.set_xticks(np.arange(0, 25, 2))
ax.set_xlabel("Hour of day")
ax.set_ylabel("% of daily peak")
ax.set_title("IEEE RTS – Typical Daily Load Profile")
ax.grid(ls="--", alpha=0.3)       # light, unobtrusive grid
plt.tight_layout()
plt.show()

Actual outcome

Image

Expected outcome

readable figures

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.4

Matplotlib Backend

No response

Python version

3.9

Jupyter version

No response

Installation

pip

@Amit9785
Copy link

Amit9785 commented May 12, 2025

Hey, I just ran your code on Google Colab using Matplotlib 3.8.4, and the plot, including the grid lines and labels, looks perfectly sharp and readable.

This makes me think the issue might be specific to your environment, possibly due to:

  1. A rendering backend (e.g., inline/Jupyter vs TkAgg)
  2. A lower screen resolution or scaling setting

You can try:

  • Increasing dpi in plt.subplots(), e.g., dpi=200
  • Saving the plot with plt.savefig("plot.png", dpi=300) to confirm sharpness
  • Switching Matplotlib backend using:_
import matplotlib
matplotlib.use("TkAgg")
Image

@rcomer
Copy link
Member

rcomer commented May 12, 2025

The problem seems to go beyond resolution/sharpness, as features are repeated (e.g "Hour of day" appears three times along the bottom). @PonySubway how are you running your code and showing the figure? If in an IDE the problem may be with the IDE rather than Matplotlib. I agree with @Amit9785 that saving directly to png or switching backend may provide some clues.

@rcomer rcomer added the status: needs clarification Issues that need more information to resolve. label May 12, 2025
@tacaswell
Copy link
Member

This looks like what ever is rendering the png is confusing [channel, row, col] order and [row, col, channel] order.

Based on the code (and no reported backend), I strongly suggest that this is a bug in what ever UI you are using and should be reported to them.

https://matplotlib.org/stable/gallery/user_interfaces/canvasagg.html is a good reference on how to do this most easily. My guess is the backend is using something like https://matplotlib.org/3.1.1/gallery/misc/agg_buffer.html and reshaping it incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

No branches or pull requests

4 participants