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

Skip to content

Commit 063c379

Browse files
committed
added rc param axes.unicode_minus
svn path=/trunk/matplotlib/; revision=6453
1 parent 66bd9bc commit 063c379

6 files changed

Lines changed: 30 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-11-25 Added rcParam axes.unicode_minus which allows plain hypen
2+
for minus when False - JDH
3+
14
2008-11-25 Added scatterpoints support in Legend. patch by Erik
25
Tollerud - JJL
36

examples/api/unicode_minus.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
You can use the proper typesetting unicode minus (see
3+
http://en.wikipedia.org/wiki/Plus_sign#Plus_sign) or the ASCII hypen
4+
for minus, which some people prefer. The matplotlibrc param
5+
axes.unicode_minus controls the default behavior.
6+
7+
The default is to use the unicode minus
8+
"""
9+
import numpy as np
10+
import matplotlib
11+
import matplotlib.pyplot as plt
12+
13+
matplotlib.rcParams['axes.unicode_minus'] = False
14+
fig = plt.figure()
15+
ax = fig.add_subplot(111)
16+
ax.plot(10*np.random.randn(100), 10*np.random.randn(100), 'o')
17+
ax.set_title('Using hypen instead of unicode minus')
18+
plt.show()

lib/matplotlib/projections/polar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def __call__(self, x, pos=None):
139139
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
140140
return r"$%d^\circ$" % ((x / npy.pi) * 180.0)
141141
else:
142+
# we use unicode, rather than mathtext with \circ, so
143+
# that it will work correctly with any arbitrary font
144+
# (assuming it has a degree sign), whereas $5\circ$
145+
# will only work correctly with one of the supported
146+
# math fonts (Computer Modern and STIX)
142147
return u"%d\u00b0" % ((x / npy.pi) * 180.0)
143148

144149
class RadialLocator(Locator):

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def __call__(self, s):
412412
# use scientific notation if log10
413413
# of the axis range is smaller than the
414414
# first or larger than the second
415+
'axes.unicode_minus' : [True, validate_bool],
415416

416417
'polaraxes.grid' : [True, validate_bool], # display polar grid or not
417418

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def __init__(self, useOffset=True, useMathText=False):
313313

314314
def fix_minus(self, s):
315315
'use a unicode minus rather than hyphen'
316-
if rcParams['text.usetex']: return s
316+
if rcParams['text.usetex'] or not rcParams['axes.unicode_minus']: return s
317317
else: return s.replace('-', u'\u2212')
318318

319319
def __call__(self, x, pos=None):

matplotlibrc.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ numerix : %(numerix)s # numpy, Numeric or numarray
205205
#axes.formatter.limits : -7, 7 # use scientific notation if log10
206206
# of the axis range is smaller than the
207207
# first or larger than the second
208+
#axes.unicode_minus : True # use unicode for the minus symbol
209+
# rather than hypen. See http://en.wikipedia.org/wiki/Plus_sign#Plus_sign
208210

209211
#polaraxes.grid : True # display grid on polar axes
210212

0 commit comments

Comments
 (0)