Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3603bf

Browse files
authored
Merge pull request #15940 from anntzer/unicode
Some unicode-support related cleanups.
2 parents ce63753 + 1cb198e commit d3603bf

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed

examples/text_labels_and_annotations/tex_demo.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
Rendering math equations using TeX
44
==================================
55
6-
You can use TeX to render all of your matplotlib text if the rc
7-
parameter ``text.usetex`` is set. This works currently on the agg and ps
8-
backends, and requires that you have tex and the other dependencies
9-
described in the :doc:`/tutorials/text/usetex` tutorial
10-
properly installed on your system. The first time you run a script
11-
you will see a lot of output from tex and associated tools. The next
12-
time, the run may be silent, as a lot of the information is cached.
13-
14-
Notice how the label for the y axis is provided using unicode!
15-
6+
You can use TeX to render all of your Matplotlib text by setting
7+
:rc:`text.usetex` to True. This requires that you have TeX and the other
8+
dependencies described in the :doc:`/tutorials/text/usetex` tutorial properly
9+
installed on your system. Matplotlib caches processed TeX expressions, so that
10+
only the first occurrence of an expression triggers a TeX compilation. Later
11+
occurrences reuse the rendered image from the cache and are thus faster.
12+
13+
Unicode input is supported, e.g. for the y-axis label in this example.
1614
"""
15+
1716
import numpy as np
1817
import matplotlib
1918
matplotlib.rcParams['text.usetex'] = True

lib/matplotlib/_layoutbox.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,31 @@ def __init__(self, parent=None, name='', tightwidth=False,
7272
# keep track of whether we need to match this subplot up with others.
7373
self.subplot = subplot
7474

75-
# we need the str below for Py 2 which complains the string is unicode
76-
self.top = Variable(str(sn + 'top'))
77-
self.bottom = Variable(str(sn + 'bottom'))
78-
self.left = Variable(str(sn + 'left'))
79-
self.right = Variable(str(sn + 'right'))
80-
81-
self.width = Variable(str(sn + 'width'))
82-
self.height = Variable(str(sn + 'height'))
83-
self.h_center = Variable(str(sn + 'h_center'))
84-
self.v_center = Variable(str(sn + 'v_center'))
85-
86-
self.min_width = Variable(str(sn + 'min_width'))
87-
self.min_height = Variable(str(sn + 'min_height'))
88-
self.pref_width = Variable(str(sn + 'pref_width'))
89-
self.pref_height = Variable(str(sn + 'pref_height'))
75+
self.top = Variable(sn + 'top')
76+
self.bottom = Variable(sn + 'bottom')
77+
self.left = Variable(sn + 'left')
78+
self.right = Variable(sn + 'right')
79+
80+
self.width = Variable(sn + 'width')
81+
self.height = Variable(sn + 'height')
82+
self.h_center = Variable(sn + 'h_center')
83+
self.v_center = Variable(sn + 'v_center')
84+
85+
self.min_width = Variable(sn + 'min_width')
86+
self.min_height = Variable(sn + 'min_height')
87+
self.pref_width = Variable(sn + 'pref_width')
88+
self.pref_height = Variable(sn + 'pref_height')
9089
# margins are only used for axes-position layout boxes. maybe should
9190
# be a separate subclass:
92-
self.left_margin = Variable(str(sn + 'left_margin'))
93-
self.right_margin = Variable(str(sn + 'right_margin'))
94-
self.bottom_margin = Variable(str(sn + 'bottom_margin'))
95-
self.top_margin = Variable(str(sn + 'top_margin'))
91+
self.left_margin = Variable(sn + 'left_margin')
92+
self.right_margin = Variable(sn + 'right_margin')
93+
self.bottom_margin = Variable(sn + 'bottom_margin')
94+
self.top_margin = Variable(sn + 'top_margin')
9695
# mins
97-
self.left_margin_min = Variable(str(sn + 'left_margin_min'))
98-
self.right_margin_min = Variable(str(sn + 'right_margin_min'))
99-
self.bottom_margin_min = Variable(str(sn + 'bottom_margin_min'))
100-
self.top_margin_min = Variable(str(sn + 'top_margin_min'))
96+
self.left_margin_min = Variable(sn + 'left_margin_min')
97+
self.right_margin_min = Variable(sn + 'right_margin_min')
98+
self.bottom_margin_min = Variable(sn + 'bottom_margin_min')
99+
self.top_margin_min = Variable(sn + 'top_margin_min')
101100

102101
right, top = upper_right
103102
left, bottom = lower_left

lib/matplotlib/projections/polar.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,10 +1362,7 @@ def set_xscale(self, scale, *args, **kwargs):
13621362
"You can not set the xscale on a polar plot.")
13631363

13641364
def format_coord(self, theta, r):
1365-
"""
1366-
Return a format string formatting the coordinate using Unicode
1367-
characters.
1368-
"""
1365+
# docstring inherited
13691366
if theta < 0:
13701367
theta += 2 * np.pi
13711368
theta /= np.pi

lib/matplotlib/tests/test_animation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ def animate(i):
169169
# per frame with known names.
170170
with tmpdir.as_cwd():
171171
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5)
172-
try:
173-
anim.save(output, fps=30, writer=writer, bitrate=500, dpi=dpi,
174-
codec=codec)
175-
except UnicodeDecodeError:
176-
pytest.xfail("There can be errors in the numpy import stack, "
177-
"see issues #1891 and #2679")
172+
anim.save(output, fps=30, writer=writer, bitrate=500, dpi=dpi,
173+
codec=codec)
178174

179175

180176
def test_no_length_frames():

0 commit comments

Comments
 (0)