Skip to content

Commit ab875ac

Browse files
committed
added latex font name to tex prefix
svn path=/trunk/matplotlib/; revision=1980
1 parent d669429 commit ab875ac

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2006-01-20 Added a converters dict to pylab load to convert selected
2+
coloumns to float -- especially useful for files with date
3+
strings, uses a datestr2num converter - JDH
4+
5+
2006-01-20 Added datestr2num to matplotlib dates to convert a string
6+
or sequence of strings to a matplotlib datenum
7+
18
2006-01-18 Added quadrilateral pcolormesh patch 1409190 by Alex Mont
29
and Paul Kienzle -- this is *Agg only for now. See
310
examples/quadmesh_demo.py - JDH

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include Makefile MANIFEST.in MANIFEST
44
include matplotlibrc.template matplotlibrc
55
include __init__.py setupext.py setup.py makeswig.py
66
include examples/data/*
7+
include lib/matplotlib/toolkits
78
include images/*
89
recursive-include fonts *
910
recursive-include license LICENSE*

examples/load_converter.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pylab import figure, show, datestr2num, load
2+
3+
4+
5+
X = load('data/msft.csv', delimiter=',',
6+
converters={0:datestr2num}, skiprows=1)
7+
dates = X[:,0]
8+
close = X[:,2]
9+
10+
fig = figure()
11+
ax = fig.add_subplot(111)
12+
ax.plot_date(dates, close)
13+
show()

lib/matplotlib/dates.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@
8484
except ImportError:
8585
raise ValueError('matplotlib %s date handling requires python2.3' % matplotlib.__version__)
8686

87-
from cbook import iterable
87+
from cbook import iterable, is_string_like
8888
from pytz import timezone
8989
from numerix import arange, asarray
9090
from ticker import Formatter, Locator, Base
9191
from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,\
9292
MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY
9393
from dateutil.relativedelta import relativedelta
94+
import dateutil.parser
9495

9596
UTC = timezone('UTC')
9697

@@ -163,6 +164,18 @@ def _from_ordinalf(x, tz=None):
163164

164165
return dt
165166

167+
def datestr2num(d):
168+
"""
169+
Convert a date string to a datenum using dateutil.parser.parse
170+
d can be a single string or a sequence of strings
171+
"""
172+
if is_string_like(d):
173+
dt = dateutil.parser.parse(d)
174+
return date2num(dt)
175+
else:
176+
return date2num([dateutil.parser.parse(s) for s in d])
177+
178+
166179
def date2num(d):
167180
"""
168181
d is either a datetime instance or a sequence of datetimes

lib/matplotlib/pylab.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
# eg a bad pytz install. I don't want to break all of matplotlib for
233233
# date support
234234
try:
235-
from dates import date2num, num2date, drange, epoch2num, num2epoch, mx2num,\
235+
from dates import date2num, num2date, datestr2num, drange, epoch2num, num2epoch, mx2num,\
236236
DateFormatter, IndexDateFormatter, DateLocator,\
237237
RRuleLocator, YearLocator, MonthLocator, WeekdayLocator,\
238238
DayLocator, HourLocator, MinuteLocator, SecondLocator,\
@@ -951,7 +951,7 @@ def imread(*args, **kwargs):
951951
imread.__doc__ = _shift_string(_imread.__doc__)
952952

953953

954-
def load(fname,comments='%',delimiter=None):
954+
def load(fname,comments='%',delimiter=None, converters=None,skiprows=0):
955955
"""
956956
Load ASCII data from fname into an array and return the array.
957957
@@ -985,8 +985,14 @@ def load(fname,comments='%',delimiter=None):
985985
file. If delimiter is unspecified or none, any whitespace string is
986986
a separator.
987987
988+
converters, if not None, is a dictionary mapping column number to
989+
a function that will convert that column to a float. Eg, if
990+
column 0 is a date string: converters={0:datestr2num}
991+
992+
skiprows is the number of rows from the top to skip
988993
"""
989994

995+
if converters is None: converters = {}
990996
if is_string_like(fname):
991997
if fname.endswith('.gz'):
992998
import gzip
@@ -999,10 +1005,11 @@ def load(fname,comments='%',delimiter=None):
9991005
raise ValueError('fname must be a string or file handle')
10001006
X = []
10011007
numCols = None
1002-
for line in fh:
1008+
for i,line in enumerate(fh):
1009+
if i<skiprows: continue
10031010
line = line[:line.find(comments)].strip()
10041011
if not len(line): continue
1005-
row = [float(val) for val in line.split(delimiter)]
1012+
row = [converters.get(i,float)(val) for i,val in enumerate(line.split(delimiter))]
10061013
thisLen = len(row)
10071014
if numCols is not None and thisLen != numCols:
10081015
raise ValueError('All rows must have the same number of columns')

lib/matplotlib/texmanager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ def __init__(self):
7474

7575

7676
def get_prefix(self, tex):
77-
return md5.md5(tex).hexdigest()
77+
s = tex
78+
if rcParams['text.tex.engine'] == 'latex':
79+
s+='latex font: %s'%rcParams['font.latex.package']
80+
return md5.md5(s).hexdigest()
7881

7982
def get_tex_command(self, tex, fname):
8083

0 commit comments

Comments
 (0)