Skip to content

Commit 9e3a451

Browse files
committed
Merged revisions 5026-5038 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_91_maint ........ r5028 | jdh2358 | 2008-04-03 11:24:20 -0400 (Thu, 03 Apr 2008) | 1 line some small fixes to excel tools ........ r5032 | jrevans | 2008-04-07 18:26:21 -0400 (Mon, 07 Apr 2008) | 2 lines Fixed the double draw bug. ........ r5033 | jdh2358 | 2008-04-09 14:54:54 -0400 (Wed, 09 Apr 2008) | 1 line small fix for vlines w/ len 1 args ........ r5038 | mdboom | 2008-04-11 11:24:57 -0400 (Fri, 11 Apr 2008) | 3 lines Fixing global font rcParam setting after initialization time (thanks to Lev Givon and Eric Firing for finding this) ........ svn path=/trunk/matplotlib/; revision=5039
1 parent e89e71d commit 9e3a451

File tree

6 files changed

+82
-80
lines changed

6 files changed

+82
-80
lines changed

CHANGELOG

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
2008-04-11 Revert commits 5002 and 5031, which were intended to
2-
avoid an unnecessary call to draw(). 5002 broke saving
1+
2008-04-11 Fix global font rcParam setting after initialization
2+
time. - MGD
3+
4+
2008-04-11 Revert commits 5002 and 5031, which were intended to
5+
avoid an unnecessary call to draw(). 5002 broke saving
36
figures before show(). 5031 fixed the problem created in
4-
5002, but broke interactive plotting. Unnecessary call to
7+
5002, but broke interactive plotting. Unnecessary call to
58
draw still needs resolution - DSD
69

710
2008-04-07 Improve color validation in rc handling, suggested

examples/rec_groupby_demo.py

+12
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
r.sort()
77

88
def daily_return(prices):
9+
'an array of daily returns from price array'
910
g = np.zeros_like(prices)
1011
g[1:] = (prices[1:]-prices[:-1])/prices[:-1]
1112
return g
1213

1314
def volume_code(volume):
15+
'code the continuous volume data categorically'
1416
ind = np.searchsorted([1e5,1e6, 5e6,10e6, 1e7], volume)
1517
return ind
1618

19+
# a list of (dtype_name, summary_function, output_dtype_name).
20+
# rec_summarize will call on each function on the indicated recarray
21+
# attribute, and the result assigned to output name in the return
22+
# record array.
1723
summaryfuncs = (
1824
('date', lambda x: [thisdate.year for thisdate in x], 'years'),
1925
('date', lambda x: [thisdate.month for thisdate in x], 'months'),
@@ -24,13 +30,18 @@ def volume_code(volume):
2430

2531
rsum = mlab.rec_summarize(r, summaryfuncs)
2632

33+
# stats is a list of (dtype_name, function, output_dtype_name).
34+
# rec_groupby will summarize the attribute identified by the
35+
# dtype_name over the groups in the groupby list, and assign the
36+
# result to the output_dtype_name
2737
stats = (
2838
('dreturn', len, 'rcnt'),
2939
('dreturn', np.mean, 'rmean'),
3040
('dreturn', np.median, 'rmedian'),
3141
('dreturn', np.std, 'rsigma'),
3242
)
3343

44+
# you can summarize over a single variable, like years or months
3445
print 'summary by years'
3546
ry = mlab.rec_groupby(rsum, ('years',), stats)
3647
print mlab. rec2txt(ry)
@@ -39,6 +50,7 @@ def volume_code(volume):
3950
rm = mlab.rec_groupby(rsum, ('months',), stats)
4051
print mlab.rec2txt(rm)
4152

53+
# or over multiple variables like years and months
4254
print 'summary by year and month'
4355
rym = mlab.rec_groupby(rsum, ('years','months'), stats)
4456
print mlab.rec2txt(rym)

lib/matplotlib/axes.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2592,10 +2592,9 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
25922592
xmax = npy.asarray(xmax)
25932593

25942594
if len(xmin)==1:
2595-
xmin = xmin*npy.ones(y.shape, y.dtype)
2595+
xmin = npy.resize( xmin, y.shape )
25962596
if len(xmax)==1:
2597-
xmax = xmax*npy.ones(y.shape, y.dtype)
2598-
2597+
xmax = npy.resize( xmax, y.shape )
25992598

26002599
if len(xmin)!=len(y):
26012600
raise ValueError, 'xmin and y are unequal sized sequences'
@@ -2660,9 +2659,9 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
26602659
ymin = npy.asarray(ymin)
26612660
ymax = npy.asarray(ymax)
26622661
if len(ymin)==1:
2663-
ymin = ymin*npy.ones(x.shape, x.dtype)
2662+
ymin = npy.resize( ymin, x.shape )
26642663
if len(ymax)==1:
2665-
ymax = ymax*npy.ones(x.shape, x.dtype)
2664+
ymax = npy.resize( ymax, x.shape )
26662665

26672666
if len(ymin)!=len(x):
26682667
raise ValueError, 'ymin and x are unequal sized sequences'

lib/matplotlib/backends/backend_qt4agg.py

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def draw( self ):
131131
if DEBUG: print "FigureCanvasQtAgg.draw", self
132132
self.replot = True
133133
FigureCanvasAgg.draw(self)
134-
self.update()
135134

136135
def blit(self, bbox=None):
137136
"""

lib/matplotlib/font_manager.py

+60-70
Original file line numberDiff line numberDiff line change
@@ -625,20 +625,6 @@ class FontProperties(object):
625625
fontconfig.
626626
"""
627627

628-
class FontPropertiesSet(object):
629-
"""This class contains all of the default properties at the
630-
class level, which are then overridden (only if provided) at
631-
the instance level."""
632-
family = rcParams['font.' + rcParams['font.family']]
633-
if is_string_like(family):
634-
family = [family]
635-
slant = [rcParams['font.style']]
636-
variant = [rcParams['font.variant']]
637-
weight = [rcParams['font.weight']]
638-
stretch = [rcParams['font.stretch']]
639-
size = [rcParams['font.size']]
640-
file = None
641-
642628
def __init__(self,
643629
family = None,
644630
style = None,
@@ -649,12 +635,17 @@ def __init__(self,
649635
fname = None, # if this is set, it's a hardcoded filename to use
650636
_init = None # used only by copy()
651637
):
652-
653-
self.__props = self.FontPropertiesSet()
638+
self._family = None
639+
self._slant = None
640+
self._variant = None
641+
self._weight = None
642+
self._stretch = None
643+
self._size = None
644+
self._file = None
654645

655646
# This is used only by copy()
656647
if _init is not None:
657-
self.__props.__dict__.update(_init)
648+
self.__dict__.update(_init.__dict__)
658649
return
659650

660651
if is_string_like(family):
@@ -666,9 +657,8 @@ def __init__(self,
666657
stretch is None and
667658
size is None and
668659
fname is None):
669-
self.__props.__dict__ = self._parse_fontconfig_pattern(family)
660+
self.set_fontconfig_pattern(family)
670661
return
671-
family = [family]
672662

673663
self.set_family(family)
674664
self.set_style(style)
@@ -682,54 +672,66 @@ def _parse_fontconfig_pattern(self, pattern):
682672
return parse_fontconfig_pattern(pattern)
683673

684674
def __hash__(self):
685-
return hash(repr(self.__props.__dict__))
675+
return hash(repr(self.__dict__))
686676

687677
def __str__(self):
688678
return self.get_fontconfig_pattern()
689679

690680
def get_family(self):
691681
"""Return a list of font names that comprise the font family.
692682
"""
693-
return self.__props.family
683+
if self._family is None:
684+
family = rcParams['font.family']
685+
if is_string_like(family):
686+
return [family]
687+
return family
688+
return self._family
694689

695690
def get_name(self):
696691
"""Return the name of the font that best matches the font properties."""
697692
return ft2font.FT2Font(str(findfont(self))).family_name
698693

699694
def get_style(self):
700695
"""Return the font style. Values are: normal, italic or oblique."""
701-
return self.__props.slant[0]
696+
if self._slant is None:
697+
return rcParams['font.style']
698+
return self._slant
702699

703700
def get_variant(self):
704701
"""Return the font variant. Values are: normal or small-caps."""
705-
return self.__props.variant[0]
702+
if self._variant is None:
703+
return rcParams['font.variant']
704+
return self._variant
706705

707706
def get_weight(self):
708707
"""
709708
Return the font weight. See the FontProperties class for a
710709
a list of possible values.
711710
"""
712-
return self.__props.weight[0]
711+
if self._weight is None:
712+
return rcParams['font.weight']
713+
return self._weight
713714

714715
def get_stretch(self):
715716
"""
716717
Return the font stretch or width. Options are: normal,
717718
narrow, condensed, or wide.
718719
"""
719-
return self.__props.stretch[0]
720+
if self._stretch is None:
721+
return rcParams['font.stretch']
722+
return self._stretch
720723

721724
def get_size(self):
722725
"""Return the font size."""
723-
return float(self.__props.size[0])
726+
if self._size is None:
727+
return rcParams['font.size']
728+
return float(self._size)
724729

725730
def get_file(self):
726-
if self.__props.file is not None:
727-
return self.__props.file[0]
728-
else:
729-
return None
731+
return self._file
730732

731733
def get_fontconfig_pattern(self):
732-
return generate_fontconfig_pattern(self.__props.__dict__)
734+
return generate_fontconfig_pattern(self)
733735

734736
def set_family(self, family):
735737
"""
@@ -738,87 +740,75 @@ def set_family(self, family):
738740
fantasy, or monospace, or a real font name.
739741
"""
740742
if family is None:
741-
self.__props.__dict__.pop('family', None)
743+
self._family = None
742744
else:
743745
if is_string_like(family):
744746
family = [family]
745-
self.__props.family = family
747+
self._family = family
746748
set_name = set_family
747749

748750
def set_style(self, style):
749751
"""Set the font style. Values are: normal, italic or oblique."""
750-
if style is None:
751-
self.__props.__dict__.pop('style', None)
752-
else:
753-
if style not in ('normal', 'italic', 'oblique'):
754-
raise ValueError("style must be normal, italic or oblique")
755-
self.__props.slant = [style]
752+
if style not in ('normal', 'italic', 'oblique', None):
753+
raise ValueError("style must be normal, italic or oblique")
754+
self._slant = style
756755

757756
def set_variant(self, variant):
758757
"""Set the font variant. Values are: normal or small-caps."""
759-
if variant is None:
760-
self.__props.__dict__.pop('variant', None)
761-
else:
762-
if variant not in ('normal', 'small-caps'):
763-
raise ValueError("variant must be normal or small-caps")
764-
self.__props.variant = [variant]
758+
if variant not in ('normal', 'small-caps', None):
759+
raise ValueError("variant must be normal or small-caps")
760+
self._variant = variant
765761

766762
def set_weight(self, weight):
767763
"""
768764
Set the font weight. See the FontProperties class for a
769765
a list of possible values.
770766
"""
771-
if weight is None:
772-
self.__props.__dict__.pop('weight', None)
773-
else:
774-
if (weight not in weight_dict and
775-
weight not in weight_dict.keys()):
776-
raise ValueError("weight is invalid")
777-
self.__props.weight = [weight]
767+
if (weight is not None and
768+
weight not in weight_dict and
769+
weight not in weight_dict.keys()):
770+
raise ValueError("weight is invalid")
771+
self._weight = weight
778772

779773
def set_stretch(self, stretch):
780774
"""
781775
Set the font stretch or width. Options are: normal, narrow,
782776
condensed, or wide.
783777
"""
784-
if stretch is None:
785-
self.__props.__dict__.pop('stretch', None)
786-
else:
787-
self.__props.stretch = [stretch]
778+
if stretch not in ('normal', 'narrow', 'condensed', 'wide', None):
779+
raise ValueError("stretch is invalid")
780+
self._stretch = stretch
788781

789782
def set_size(self, size):
790783
"""Set the font size."""
791784
if size is None:
792-
self.__props.__dict__.pop('size', None)
785+
self._size = None
793786
else:
794787
if is_string_like(size):
795788
parent_size = fontManager.get_default_size()
796789
scaling = font_scalings.get(size)
797790
if scaling is not None:
798791
size = parent_size * scaling
799792
else:
800-
size = parent_size
801-
if isinstance(size, (int, float)):
802-
size = [size]
803-
self.__props.size = size
793+
try:
794+
size = float(size)
795+
except ValueError:
796+
size = parent_size
797+
assert(type(size) in (int, float))
798+
self._size = size
804799

805800
def set_file(self, file):
806-
if file is None:
807-
self.__props.__dict__.pop('file', None)
808-
else:
809-
self.__props.file = [file]
801+
self._file = file
810802

811803
get_size_in_points = get_size
812804

813805
def set_fontconfig_pattern(self, pattern):
814-
self.__props.__dict__ = self._parse_fontconfig_pattern(pattern)
815-
816-
def add_property_pair(self, key, val):
817-
self.__props.setdefault(key, []).append(val)
806+
for key, val in self._parse_fontconfig_pattern(pattern).items():
807+
getattr(self, "set_" + key)(val)
818808

819809
def copy(self):
820810
"""Return a deep copy of self"""
821-
return FontProperties(_init = self.__props.__dict__)
811+
return FontProperties(_init = self)
822812

823813
def ttfdict_to_fnames(d):
824814
'flatten a ttfdict to all the filenames it contains'

lib/matplotlib/mlab.py

-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,6 @@ def safe_isinf(x):
19481948
except NotImplementedError: return False
19491949
else: return b
19501950

1951-
19521951
def rec_append_field(rec, name, arr, dtype=None):
19531952
'return a new record array with field name populated with data from array arr'
19541953
arr = npy.asarray(arr)

0 commit comments

Comments
 (0)