-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Backgroundcolor of text is set in a too wide range #29874
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
Comments
The background is realized through an internal What happens here is that the patch is created with finite linewidth 1 and the edgecolor is the same as the facecolor (One can debate whether that behavior is reasonable, but it likely needs a closer look to handle all potential cases reasonably). To completely undo |
Note: The behavior is due to matplotlib/lib/matplotlib/text.py Line 995 in 33dbc47
There is a need to do something about the edge because by default |
Thanks for your reply. For an user of matplotlib like me it is hard to guess, that the problem of the red border results from the initialization of the text object and how to work around. I got another problem, probably caused by the initialization of text object, which is more hard to understand for the user. ----------------------------import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) txt = ax.text(0.1, 0.8, 'My Text ...') Make it work with the "workaround of backgroundcolor":txt.set(backgroundcolor='none') plt.show() |
Could we instead set edgecolor to "none"? If I understand correctly, that is the default for a patch these days anyway (though it is black in classic mode). |
Another option might be to set the edgecolor to match facecolor here matplotlib/lib/matplotlib/text.py Line 997 in 33dbc47
Then matplotlib/lib/matplotlib/patches.py Lines 406 to 420 in 6fc8169
|
That would be a bit counter-intuitive to me. My mental model is that the text background color is only the fill and does not affect the frame. E.g. when I have
I would expect that the black frame stays. I also like that the box has sharp color edges when no edge line is used. The boundary line is antialiased and blurs the edges. |
Bug summary
Backgroundcolor of text is set in a too wide range when setting it for the first time.
Problem: Border of first color remains when backgroundcolor is set again.
Code for reproduction
Actual outcome
Text with red border, see picture above.
Expected outcome
Text without red border.
Additional information
There is a workaround for the first, but not a fix, see Python program above.
Operating system
Windows
Matplotlib Version
3.10.1
Matplotlib Backend
tkagg
Python version
3.13.2
Jupyter version
Installation
pip
The text was updated successfully, but these errors were encountered: