Title: Support customizing antialiasing for text and annotation by stevezhang1999 · Pull Request #25775 · matplotlib/matplotlib · GitHub
Open Graph Title: Support customizing antialiasing for text and annotation by stevezhang1999 · Pull Request #25775 · matplotlib/matplotlib
X Title: Support customizing antialiasing for text and annotation by stevezhang1999 · Pull Request #25775 · matplotlib/matplotlib
Description: PR Summary Closes #25675 Change overview: now text objects and annotation objects support parameter 'antialiased'. When antialiased is not specified, it will use the value from rcParams instead. Examples are mpl.text.Text(.5, .5, "foo\nbar", antialiased=True) plt.text(0.5, 0.5, '6 inches x 2 inches', antialiased=True) ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), antialiased=False) how it is done It's realized by changing how antialiased is set in backends - draw_text() in backend_agg.py. Now we use GraphicsContext.get_antialiased() instead of rcParams['text.antialiased'] GraphicsContext object is retrieved and updated by Text and Annotation objects when draw() is called limitations Currently, it's only supported by Agg and Cairo backend. For all other backends, I didn't see they are checking rcParams['text.antialiased'] to customize text antialiasing. Note that to set antialiasing for math expressions, the only way is still using rcParams['text.antialiased'], as the process is a bit different from normal text (including annotation) notes for tests Unit tests ensure that getter/setter in Text and Annotation objects works well. I didn't include the tests for the whole pipeline because it may require uploading images. The integration test code is below - we are expected to see texts without antialiasing. The code below is for Agg. If we wnat to test with Cairo, please replace 'TkAgg' with 'GTK3Cairo' in line 14 import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import sys def is_venv(): return (hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)) print("Inside venv: ", is_venv()) mpl.use('TkAgg') print("backend: ", mpl.rcParams['backend']) print("*"*10, "simple unit test", "*"*10) txt2 = mpl.text.Text(.5, .5, "foo\nbar", antialiased=True) print("txt2.get_antialiased(): ", txt2.get_antialiased()) print("*"*35) print("Test: plt.text") mpl.rcParams['text.antialiased'] = True text_kwargs = dict(ha='center', va='center', fontsize=28, color='C1', antialiased=False) plt.subplots(figsize=(6, 2)) plt.text(0.5, 0.5, '6 inches x 2 inches', **text_kwargs) plt.show() fig, ax = plt.subplots(figsize=(3, 3)) t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) line, = ax.plot(t, s, lw=2) print("Test: ax.annotate") mpl.rcParams['text.antialiased'] = True ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05), antialiased=False) ax.set_ylim(-2, 2) plt.show() PR Checklist Linked Issue Added "closes #0000" in the PR description to link it to the original issue. Documentation and Tests Has pytest style unit tests (and pytest passes) units tests for new getter and setter for attribute "antialiased" integrate tests for run the whole thing, please see the scripts at the end Documentation is sphinx and numpydoc compliant (the docs should build without error). N/A - no doc added New plotting related features are documented with examples. N/A - docstring already have antialiased, modification is not needed
Open Graph Description: PR Summary Closes #25675 Change overview: now text objects and annotation objects support parameter 'antialiased'. When antialiased is not specified, it will use the value from rcParams ins...
X Description: PR Summary Closes #25675 Change overview: now text objects and annotation objects support parameter 'antialiased'. When antialiased is not specified, it will use the value from rcPa...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/25775
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7f12c21b-5f41-5892-704a-a66452e045ac |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8A5E:DFD60:12B49AA:18C6C6B:6A542A54 |
| html-safe-nonce | 67a06139b78b246d312f4bee115619c6a59222b077ca18cba6fe683dbda2e36a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTVFOkRGRDYwOjEyQjQ5QUE6MThDNkM2Qjo2QTU0MkE1NCIsInZpc2l0b3JfaWQiOiI2MzUzNDAxMDkxMDI4NDI5Mzk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 41ea0eaa34d6f292f8b01487a2e3b220f0b92211499b636d7fb68b5ee9b438af |
| hovercard-subject-tag | pull_request:1329406960 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/25775/files |
| twitter:image | https://avatars.githubusercontent.com/u/38875181?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/38875181?s=400&v=4 |
| og:image:alt | PR Summary Closes #25675 Change overview: now text objects and annotation objects support parameter 'antialiased'. When antialiased is not specified, it will use the value from rcParams ins... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width