-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support customizing antialiasing for text and annotation #25775
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
Merged
oscargus
merged 4 commits into
matplotlib:main
from
stevezhang1999:text-object-antialias
Jun 2, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
18c7a4b
Support customizing antialiasing for text and annotation
5e5a03d
streamlined image comparison tests for text antialiasing
stevezhang1999 5e3bab4
fix doc formatting, parameter name and spells
stevezhang1999 95e0709
update text.pyi
stevezhang1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Default antialiasing behavior changes for ``Text`` and ``Annotation`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
``matplotlib.pyplot.annotate()`` and ``matplotlib.pyplot.text()`` now support parameter *antialiased* when initializing. | ||
Examples: | ||
|
||
.. code-block:: | ||
|
||
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) | ||
|
||
See "What's New" for more details on usage. | ||
|
||
With this new feature, you may want to make sure that you are creating and saving/showing the figure under the same context:: | ||
|
||
# previously this was a no-op, now it is what works | ||
with rccontext(text.antialiased=False): | ||
fig, ax = plt.subplots() | ||
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) | ||
fig.savefig('/tmp/test.png') | ||
|
||
# previously this had an effect, now this is a no-op | ||
fig, ax = plt.subplots() | ||
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) | ||
with rccontext(text.antialiased=False): | ||
fig.savefig('/tmp/test.png') | ||
|
||
Also note that antialiasing for tick labels will be set with :rc:`text.antialiased` when they are created (usually when a ``Figure`` is created) - This means antialiasing for them can no longer be changed by modifying :rc:`text.antialiased`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Support customizing antialiasing for text and annotation | ||
-------------------------------------------------------- | ||
``matplotlib.pyplot.annotate()`` and ``matplotlib.pyplot.text()`` now support parameter *antialiased*. | ||
When *antialiased* is set to ``True``, antialiasing will be applied to the text. | ||
When *antialiased* is set to ``False``, antialiasing will not be applied to the text. | ||
When *antialiased* is not specified, antialiasing will be set by :rc:`text.antialiased` at the creation time of ``Text`` and ``Annotation`` object. | ||
Examples: | ||
|
||
.. code-block:: | ||
|
||
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) | ||
|
||
If the text contains math expression, then antialiasing will be set by :rc:`text.antialiased`, and *antialiased* will have no effect | ||
This applies to the whole text. | ||
Examples: | ||
|
||
.. code-block:: | ||
|
||
# no part will be antialiased for the text below | ||
plt.text(0.5, 0.25, r"$I'm \sqrt{x}$", antialiased=False) | ||
|
||
Also note that antialiasing for tick labels will be set with :rc:`text.antialiased` when they are created (usually when a ``Figure`` is created) and cannot be changed afterwards. | ||
|
||
Furthermore, with this new feature, you may want to make sure that you are creating and saving/showing the figure under the same context:: | ||
|
||
# previously this was a no-op, now it is what works | ||
with rccontext(text.antialiased=False): | ||
fig, ax = plt.subplots() | ||
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) | ||
fig.savefig('/tmp/test.png') | ||
|
||
|
||
# previously this had an effect, now this is a no-op | ||
fig, ax = plt.subplots() | ||
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) | ||
with rccontext(text.antialiased=False): | ||
fig.savefig('/tmp/test.png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.