|
1 | 1 | Support customizing antialiasing for text and annotation
|
2 |
| -~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
3 | 3 |
|
4 |
| -APIs: |
5 |
| -https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text |
6 |
| -https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.annotate.html |
7 | 4 |
|
8 |
| -Text objects and annotation objects now support parameter `antialiased`. |
9 |
| -When `antialiased` is set to `True`, antialiasing will be applied to the text. |
10 |
| -When `antialiased` is set to `False`, antialiasing will be applied to the text. |
11 |
| -When `antialiased` is not specified, it will use the value from `rcParams['text.antialiased']`. |
| 5 | + |
| 6 | +``matplotlib.pyplot.annotate()`` and ``matplotlib.pyplot.text()`` now support parameter ``antialiased``. |
| 7 | +When ``antialiased`` is set to ``True``, antialiasing will be applied to the text. |
| 8 | +When ``antialiased`` is set to ``False``, antialiasing will be applied to the text. |
| 9 | +When ``antialiased`` is not specified, it will use the value from ``rcParams['text.antialiased']``. |
12 | 10 |
|
13 | 11 | Examples:
|
14 |
| -``` |
15 |
| -mpl.text.Text(.5, .5, "foo\nbar", antialiased=True) |
16 |
| -plt.text(0.5, 0.5, '6 inches x 2 inches', antialiased=True) |
17 |
| -ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), antialiased=False) |
18 |
| -``` |
19 | 12 |
|
20 |
| -If the text contains math expression, then anaialiasing will be applied by `rcParams['text.antialiased']` and `antialiased` will have no effect |
| 13 | +.. code-block:: |
| 14 | +
|
| 15 | + mpl.text.Text(.5, .5, "foo\nbar", antialiased=True) |
| 16 | + plt.text(0.5, 0.5, '6 inches x 2 inches', antialiased=True) |
| 17 | + ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), antialiased=False) |
| 18 | +
|
| 19 | +If the text contains math expression, then anaialiasing will be applied by ``rcParams['text.antialiased']`` and ``antialiased`` will have no effect |
21 | 20 | This applies to the whole text.
|
22 | 21 | Examples:
|
23 |
| -``` |
24 |
| -plt.text(0.5, 0.25, r"$I'm \sqrt{x}$", antialiased=False) |
25 |
| -``` |
26 | 22 |
|
27 |
| -Also note that antialiasing for coordinate axes will be set with `rcParams['text.antialiased']` when they are created and cannot be changed afterwards. |
| 23 | +.. code-block:: |
28 | 24 |
|
29 |
| -With this new feature, you may want to make sure that you are creating and saving/showing the figure under the same context: |
30 |
| -``` |
31 |
| -# previously this was a no-op, now it is what works |
32 |
| -with rccontext(text.antialiased=False): |
33 |
| - fig, ax = plt.subplots() |
34 |
| - ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) |
35 |
| - fig.savefig('/tmp/test.png') |
| 25 | + plt.text(0.5, 0.25, r"$I'm \sqrt{x}$", antialiased=False) |
36 | 26 |
|
| 27 | +Also note that antialiasing for coordinate axes will be set with ``rcParams['text.antialiased']`` when they are created and cannot be changed afterwards. |
37 | 28 |
|
38 |
| -# previously this had an effect, now this is a no-op |
39 |
| -fig, ax = plt.subplots() |
40 |
| -ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) |
41 |
| -with rccontext(text.antialiased=False): |
42 |
| - fig.savefig('/tmp/test.png') |
43 |
| -``` |
| 29 | +With this new feature, you may want to make sure that you are creating and saving/showing the figure under the same context:: |
| 30 | + |
| 31 | + # previously this was a no-op, now it is what works |
| 32 | + with rccontext(text.antialiased=False): |
| 33 | + fig, ax = plt.subplots() |
| 34 | + ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) |
| 35 | + fig.savefig('/tmp/test.png') |
| 36 | + |
| 37 | + |
| 38 | + # previously this had an effect, now this is a no-op |
| 39 | + fig, ax = plt.subplots() |
| 40 | + ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5)) |
| 41 | + with rccontext(text.antialiased=False): |
| 42 | + fig.savefig('/tmp/test.png') |
0 commit comments