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

Skip to content

Commit 81290e0

Browse files
committed
Merged revisions 4244-4289 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4248 | dsdale | 2007-11-13 11:39:12 -0500 (Tue, 13 Nov 2007) | 2 lines modify formatting of comments in matplotlib.conf ........ r4249 | dsdale | 2007-11-13 13:10:32 -0500 (Tue, 13 Nov 2007) | 2 lines fixed some formatting issues in tconfig ........ r4264 | efiring | 2007-11-14 02:45:12 -0500 (Wed, 14 Nov 2007) | 2 lines A step towards a fast rectilinear pcolor version ........ r4267 | mdboom | 2007-11-14 08:58:08 -0500 (Wed, 14 Nov 2007) | 3 lines Fix bug when clicking "Cancel" in the save dialog in TkAgg backend. (Thanks Michael Zell). ........ r4268 | mdboom | 2007-11-14 09:00:56 -0500 (Wed, 14 Nov 2007) | 2 lines Fix bug in specgram. (Thanks Glen W. Mabey!) ........ r4275 | jdh2358 | 2007-11-14 11:39:47 -0500 (Wed, 14 Nov 2007) | 2 lines added glen's Fc specteal patch ........ r4278 | efiring | 2007-11-14 13:10:00 -0500 (Wed, 14 Nov 2007) | 2 lines Use mpl standard import idiom in image.py ........ r4287 | mdboom | 2007-11-14 14:06:52 -0500 (Wed, 14 Nov 2007) | 2 lines Fix placement of rotated text in Wx backend (thanks Michael Day). ........ r4288 | jdh2358 | 2007-11-14 14:11:54 -0500 (Wed, 14 Nov 2007) | 2 lines fixed is_string_like and removed is_file_like ........ r4289 | mdboom | 2007-11-14 14:25:46 -0500 (Wed, 14 Nov 2007) | 2 lines Refactored a bunch of places to use "is_writable_file_like". ........ svn path=/branches/transforms/; revision=4292
1 parent 943c749 commit 81290e0

27 files changed

Lines changed: 447 additions & 213 deletions

API_CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ TRANSFORMS REFACTORING
169169

170170
END OF TRANSFORMS REFACTORING
171171

172+
Changed cbook.is_file_like to cbook.is_writable_file_like and
173+
corrected behavior.
174+
172175
Moved mlab.csv2rec -> recutils.csv2rec
173176

174177
Added ax kwarg to pyplot.colorbar and Figure.colorbar so that

lib/matplotlib/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def enumerate(seq):
118118

119119

120120
def is_string_like(obj):
121-
if hasattr(obj, 'shape'): return 0 # this is a workaround
122-
# for a bug in numeric<23.1
121+
if hasattr(obj, 'shape'): return 0
123122
try: obj + ''
124123
except (TypeError, ValueError): return 0
125124
return 1

lib/matplotlib/axes.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,7 +4413,7 @@ def imshow(self, I,
44134413
origin=None, extent=None)
44144414
44154415
IMSHOW(I) - plot image I to current axes, resampling to scale to axes
4416-
size (I may be numarray/Numeric array or PIL image)
4416+
size (I may be numpy array or PIL image)
44174417
44184418
IMSHOW(I, X, Y) - plot image I to current axes, with
44194419
nonuniform X and Y axes. (I, X and Y may be
@@ -4988,10 +4988,10 @@ def hist(self, x, bins=10, normed=0, bottom=None,
49884988
return n, bins, cbook.silent_list('Patch', patches)
49894989
hist.__doc__ = cbook.dedent(hist.__doc__) % martist.kwdocd
49904990

4991-
def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
4991+
def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
49924992
window=mlab.window_hanning, noverlap=0, **kwargs):
49934993
"""
4994-
PSD(x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
4994+
PSD(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
49954995
window=mlab.window_hanning, noverlap=0, **kwargs)
49964996
49974997
The power spectral density by Welches average periodogram method. The
@@ -5002,22 +5002,27 @@ def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
50025002
with a scaling to correct for power loss due to windowing. Fs is the
50035003
sampling frequency.
50045004
5005-
NFFT is the length of the fft segment; must be a power of 2
5005+
* NFFT is the length of the fft segment; must be a power of 2
50065006
5007-
Fs is the sampling frequency.
5007+
* Fs is the sampling frequency.
50085008
5009-
detrend - the function applied to each segment before fft-ing,
5009+
* Fc is the center frequency of x (defaults to 0), which offsets
5010+
the yextents of the image to reflect the frequency range used
5011+
when a signal is acquired and then filtered and downsampled to
5012+
baseband.
5013+
5014+
* detrend - the function applied to each segment before fft-ing,
50105015
designed to remove the mean or linear trend. Unlike in matlab,
50115016
where the detrend parameter is a vector, in matplotlib is it a
50125017
function. The mlab module defines detrend_none, detrend_mean,
50135018
detrend_linear, but you can use a custom function as well.
50145019
5015-
window - the function used to window the segments. window is a
5020+
* window - the function used to window the segments. window is a
50165021
function, unlike in matlab(TM) where it is a vector. mlab defines
50175022
window_none, window_hanning, but you can use a custom function
50185023
as well.
50195024
5020-
noverlap gives the length of the overlap between segments.
5025+
* noverlap gives the length of the overlap between segments.
50215026
50225027
Returns the tuple Pxx, freqs
50235028
@@ -5035,6 +5040,7 @@ def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
50355040
if not self._hold: self.cla()
50365041
pxx, freqs = mlab.psd(x, NFFT, Fs, detrend, window, noverlap)
50375042
pxx.shape = len(freqs),
5043+
freqs += Fc
50385044

50395045
self.plot(freqs, 10*npy.log10(pxx), **kwargs)
50405046
self.set_xlabel('Frequency')
@@ -5052,10 +5058,10 @@ def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
50525058
return pxx, freqs
50535059
psd.__doc__ = cbook.dedent(psd.__doc__) % martist.kwdocd
50545060

5055-
def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
5061+
def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
50565062
window=mlab.window_hanning, noverlap=0, **kwargs):
50575063
"""
5058-
CSD(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
5064+
CSD(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
50595065
window=window_hanning, noverlap=0, **kwargs)
50605066
50615067
The cross spectral density Pxy by Welches average periodogram method.
@@ -5081,6 +5087,7 @@ def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
50815087
pxy, freqs = mlab.csd(x, y, NFFT, Fs, detrend, window, noverlap)
50825088
pxy.shape = len(freqs),
50835089
# pxy is complex
5090+
freqs += Fc
50845091

50855092
self.plot(freqs, 10*npy.log10(npy.absolute(pxy)), **kwargs)
50865093
self.set_xlabel('Frequency')
@@ -5097,11 +5104,10 @@ def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
50975104
return pxy, freqs
50985105
csd.__doc__ = cbook.dedent(csd.__doc__) % martist.kwdocd
50995106

5100-
def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
5107+
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
51015108
window=mlab.window_hanning, noverlap=0, **kwargs):
51025109
"""
5103-
COHERE(x, y, NFFT=256, Fs=2,
5104-
detrend = mlab.detrend_none,
5110+
COHERE(x, y, NFFT=256, Fs=2, Fc=0, detrend = mlab.detrend_none,
51055111
window = mlab.window_hanning, noverlap=0, **kwargs)
51065112
51075113
cohere the coherence between x and y. Coherence is the normalized
@@ -5126,6 +5132,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
51265132
"""
51275133
if not self._hold: self.cla()
51285134
cxy, freqs = mlab.cohere(x, y, NFFT, Fs, detrend, window, noverlap)
5135+
freqs += Fc
51295136

51305137
self.plot(freqs, cxy, **kwargs)
51315138
self.set_xlabel('Frequency')
@@ -5135,11 +5142,11 @@ def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
51355142
return cxy, freqs
51365143
cohere.__doc__ = cbook.dedent(cohere.__doc__) % martist.kwdocd
51375144

5138-
def specgram(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
5145+
def specgram(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
51395146
window=mlab.window_hanning, noverlap=128,
51405147
cmap = None, xextent=None):
51415148
"""
5142-
SPECGRAM(x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
5149+
SPECGRAM(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
51435150
window = mlab.window_hanning, noverlap=128,
51445151
cmap=None, xextent=None)
51455152
@@ -5181,7 +5188,8 @@ def specgram(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none,
51815188

51825189
if xextent is None: xextent = 0, npy.amax(bins)
51835190
xmin, xmax = xextent
5184-
extent = xmin, xmax, npy.amin(freqs), npy.amax(freqs)
5191+
freqs += Fc
5192+
extent = xmin, xmax, freqs[0], freqs[-1]
51855193
im = self.imshow(Z, cmap, extent=extent)
51865194
self.axis('auto')
51875195

lib/matplotlib/backends/backend_agg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
* allow save to file handle
2020
2121
* integrate screen dpi w/ ppi and text
22-
23-
INSTALLING
2422
"""
2523
from __future__ import division
2624
import os, sys, weakref

lib/matplotlib/backends/backend_gtk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
1919
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
2020
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors
2121
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
22-
from matplotlib.cbook import is_string_like, enumerate
22+
from matplotlib.cbook import is_string_like, is_writable_file_like, enumerate
2323
from matplotlib.colors import colorConverter
2424
from matplotlib.figure import Figure
2525
from matplotlib.widgets import SubplotTool
@@ -370,7 +370,7 @@ def _print_image(self, filename, format):
370370
pixbuf.save(filename, format)
371371
except gobject.GError, exc:
372372
error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
373-
elif hasattr(filename, 'write') and callable(filename.write):
373+
elif is_writable_file_like(filename):
374374
if hasattr(pixbuf, 'save_to_callback'):
375375
def save_callback(buf, data=None):
376376
data.write(buf)

lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from matplotlib._pylab_helpers import Gcf
2525
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
2626
FigureManagerBase, FigureCanvasBase
27-
from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict, get_realpath_and_stat
27+
from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict, \
28+
get_realpath_and_stat, is_writable_file_like
2829
from matplotlib.figure import Figure
2930
from matplotlib.font_manager import findfont, is_opentype_cff_font
3031
from matplotlib.afm import AFM
@@ -333,7 +334,7 @@ def __init__(self, width, height, filename):
333334
self.passed_in_file_object = False
334335
if is_string_like(filename):
335336
fh = file(filename, 'wb')
336-
elif hasattr(filename, 'write') and callable(filename.write):
337+
elif is_writable_file_like(filename):
337338
fh = filename
338339
self.passed_in_file_object = True
339340
else:

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
1515
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
1616
FigureManagerBase, FigureCanvasBase
1717

18-
from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat
18+
from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat, \
19+
is_writable_file_like
1920
from matplotlib.figure import Figure
2021

2122
from matplotlib.font_manager import findfont, is_opentype_cff_font
@@ -873,7 +874,7 @@ def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
873874
if is_string_like(outfile):
874875
title = outfile
875876
tmpfile = os.path.join(gettempdir(), md5.md5(outfile).hexdigest())
876-
elif hasattr(outfile, 'write') and callable(outfile.write):
877+
elif is_writable_file_like(outfile):
877878
title = None
878879
tmpfile = os.path.join(gettempdir(), md5.md5(str(hash(outfile))).hexdigest())
879880
passed_in_file_object = True

lib/matplotlib/backends/backend_svg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from matplotlib import verbose, __version__, rcParams
66
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
77
FigureManagerBase, FigureCanvasBase
8-
from matplotlib.cbook import is_string_like
8+
from matplotlib.cbook import is_string_like, is_writable_file_like
99
from matplotlib.colors import rgb2hex
1010
from matplotlib.figure import Figure
1111
from matplotlib.font_manager import findfont, FontProperties
@@ -503,7 +503,7 @@ class FigureCanvasSVG(FigureCanvasBase):
503503
def print_svg(self, filename, *args, **kwargs):
504504
if is_string_like(filename):
505505
fh_to_close = svgwriter = codecs.open(filename, 'w', 'utf-8')
506-
elif hasattr(filename, 'write') and callable(filename.write):
506+
elif is_writable_file_like(filename):
507507
svgwriter = codecs.EncodedFile(filename, 'utf-8')
508508
fh_to_close = None
509509
else:
@@ -514,7 +514,7 @@ def print_svgz(self, filename, *args, **kwargs):
514514
if is_string_like(filename):
515515
gzipwriter = gzip.GzipFile(filename, 'w')
516516
fh_to_close = svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8')
517-
elif hasattr(filename, 'write') and callable(filename.write):
517+
elif is_writable_file_like(filename):
518518
fh_to_close = gzipwriter = gzip.GzipFile(fileobj=filename, mode='w')
519519
svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8')
520520
else:

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def save_figure(self):
680680
defaultextension = self.canvas.get_default_filetype()
681681
)
682682

683-
if fname == "" :
683+
if fname == "" or fname == ():
684684
return
685685
else:
686686
try:

lib/matplotlib/backends/backend_wx.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def write(self, msg):
152152
cursors
153153
from matplotlib._pylab_helpers import Gcf
154154
from matplotlib.artist import Artist
155-
from matplotlib.cbook import exception_to_str, is_string_like
155+
from matplotlib.cbook import exception_to_str, is_string_like, is_writable_file_like
156156
from matplotlib.figure import Figure
157157
from matplotlib.path import Path
158158
from matplotlib.text import _process_text_args, Text
@@ -343,8 +343,10 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
343343
if angle == 0.0:
344344
gfx_ctx.DrawText(s, x, y)
345345
else:
346-
angle = angle * (math.pi / 180.0)
347-
gfx_ctx.DrawRotatedText(s, x, y, angle)
346+
angle = angle / 180.0 * math.pi
347+
xo = h * math.sin(rads)
348+
yo = h * math.cos(rads)
349+
gfx_ctx.DrawRotatedText(s, x - xo, y - yo, angle)
348350

349351
gc.unselect()
350352

@@ -976,7 +978,7 @@ def _print_image(self, filename, filetype, *args, **kwargs):
976978
# the error on a call or print_figure may not work because
977979
# printing can be qued and called from realize
978980
raise RuntimeError('Could not save figure to %s\n' % (filename))
979-
elif hasattr(filename, 'write') and callable(filename.write):
981+
elif is_writable_file_like(filename):
980982
if not self.bitmap.ConvertToImage().SaveStream(filename, filetype):
981983
DEBUG_MSG('print_figure() file save error', 4, self)
982984
raise RuntimeError('Could not save figure to %s\n' % (filename))

0 commit comments

Comments
 (0)