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