|
From: <jd...@us...> - 2008-06-09 17:01:21
|
Revision: 5433
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5433&view=rev
Author: jdh2358
Date: 2008-06-09 10:00:08 -0700 (Mon, 09 Jun 2008)
Log Message:
-----------
applied gregors agg resample patch
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/doc/api/artist_api.rst
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/image.py
trunk/matplotlib/lib/matplotlib/mlab.py
trunk/matplotlib/lib/matplotlib/patches.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/src/_image.cpp
trunk/matplotlib/src/_image.h
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/CHANGELOG 2008-06-09 17:00:08 UTC (rev 5433)
@@ -1,3 +1,7 @@
+2008-06-09 Committed Gregor's image resample patch to downsampling
+ images with new rcparam image.resample - JDH
+
+
2008-06-09 Don't install Enthought.Traits along with matplotlib. For
matplotlib developers convenience, it can still be
installed by setting an option in setup.cfg while we figure
@@ -3,4 +7,5 @@
decide if there is a future for the traited config - DSD
+
2008-06-09 Added range keyword arg to hist() - MM
Modified: trunk/matplotlib/doc/api/artist_api.rst
===================================================================
--- trunk/matplotlib/doc/api/artist_api.rst 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/doc/api/artist_api.rst 2008-06-09 17:00:08 UTC (rev 5433)
@@ -1,6 +1,6 @@
-******************
+*******************
matplotlib artists
-******************
+*******************
:mod:`matplotlib.artist`
=============================
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-06-09 17:00:08 UTC (rev 5433)
@@ -4974,7 +4974,7 @@
def imshow(self, X, cmap=None, norm=None, aspect=None,
interpolation=None, alpha=1.0, vmin=None, vmax=None,
origin=None, extent=None, shape=None, filternorm=1,
- filterrad=4.0, imlim=None, **kwargs):
+ filterrad=4.0, imlim=None, resample=None, **kwargs):
"""
call signature::
@@ -5061,7 +5061,7 @@
self.set_aspect(aspect)
im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
filternorm=filternorm,
- filterrad=filterrad, **kwargs)
+ filterrad=filterrad, resample=resample, **kwargs)
im.set_data(X)
im.set_alpha(alpha)
@@ -5666,9 +5666,13 @@
Keyword arguments:
bins:
+
either an integer number of bins or a sequence giving the
- bins. x are the data to be binned. x can be an array or a 2D
- array with multiple data in its columns.
+ bins. x are the data to be binned. x can be an array or a
+ 2D array with multiple data in its columns. Note, if bins
+ is an integer input argument=numbins, numbins+1 bin edges
+ will be returned, compatabile with the semantics of
+ np.histogram with the new=True argument.
range:
The lower and upper range of the bins. Lower and upper outliers
@@ -5726,6 +5730,45 @@
kwargs are used to update the properties of the
hist Rectangles:
%(Rectangle)s
+
+
+ Here is an example which generates a histogram of normally
+ distributed random numbers and plot the analytic PDF over it::
+
+
+ import numpy as np
+ import matplotlib.pyplot as plt
+ import matplotlib.mlab as mlab
+
+ mu, sigma = 100, 15
+ x = mu + sigma * np.random.randn(10000)
+
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+
+ # the histogram of the data
+ n, bins, patches = ax.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
+
+ # hist uses np.histogram under the hood to create 'n' and 'bins'.
+ # np.histogram returns the bin edges, so there will be 50 probability
+ # density values in n, 51 bin edges in bins and 50 patches. To get
+ # everything lined up, we'll compute the bin centers
+ bincenters = 0.5*(bins[1:]+bins[:-1])
+
+ # add a 'best fit' line for the normal PDF
+ y = mlab.normpdf( bincenters, mu, sigma)
+ l = ax.plot(bincenters, y, 'r--', linewidth=1)
+
+ ax.set_xlabel('Smarts')
+ ax.set_ylabel('Probability')
+ ax.set_title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
+ ax.set_xlim(40, 160)
+ ax.set_ylim(0, 0.03)
+ ax.grid(True)
+
+ #fig.savefig('histogram_demo',dpi=72)
+ plt.show()
+
"""
if not self._hold: self.cla()
Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/lib/matplotlib/image.py 2008-06-09 17:00:08 UTC (rev 5433)
@@ -57,6 +57,7 @@
extent=None,
filternorm=1,
filterrad=4.0,
+ resample = False,
**kwargs
):
@@ -86,6 +87,7 @@
self.set_interpolation(interpolation)
+ self.set_resample(resample)
self.axes = ax
@@ -200,6 +202,7 @@
im.set_interpolation(self._interpd[self._interpolation])
+ im.set_resample(self._resample)
# the viewport translation
tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
@@ -325,6 +328,13 @@
raise ValueError('Illegal interpolation string')
self._interpolation = s
+ def set_resample(self, v):
+ if v is None: v = rcParams['image.resample']
+ self._resample = v
+
+ def get_interpolation(self):
+ return self._resample
+
def get_extent(self):
'get the image extent: left, right, bottom, top'
if self._extent is not None:
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mlab.py 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2008-06-09 17:00:08 UTC (rev 5433)
@@ -716,7 +716,7 @@
def normpdf(x, *args):
"Return the normal pdf evaluated at x; args provides mu, sigma"
mu, sigma = args
- return 1/(np.sqrt(2*np.pi)*sigma)*np.exp(-0.5 * (1/sigma*(x - mu))**2)
+ return 1./(np.sqrt(2*np.pi)*sigma)*np.exp(-0.5 * (1./sigma*(x - mu))**2)
def levypdf(x, gamma, alpha):
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2008-06-09 17:00:08 UTC (rev 5433)
@@ -34,6 +34,7 @@
visible [True | False]
zorder any number
================= ==============================================
+
"""
class Patch(artist.Artist):
"""
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-06-09 17:00:08 UTC (rev 5433)
@@ -379,6 +379,7 @@
'image.cmap' : ['jet', str], # one of gray, jet, etc
'image.lut' : [256, validate_int], # lookup table
'image.origin' : ['upper', str], # lookup table
+ 'image.resample' : [False, validate_bool],
'contour.negative_linestyle' : ['dashed', validate_negative_linestyle_legacy],
Modified: trunk/matplotlib/src/_image.cpp
===================================================================
--- trunk/matplotlib/src/_image.cpp 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/src/_image.cpp 2008-06-09 17:00:08 UTC (rev 5433)
@@ -426,11 +426,22 @@
case HAMMING: filter.calculate(agg::image_filter_hamming(), norm); break;
case HERMITE: filter.calculate(agg::image_filter_hermite(), norm); break;
}
- typedef agg::span_image_filter_rgba_2x2<img_accessor_type, interpolator_type> span_gen_type;
- typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
- span_gen_type sg(ia, interpolator, filter);
- renderer_type ri(rb, sa, sg);
- agg::render_scanlines(ras, sl, ri);
+ if (resample)
+ {
+ typedef agg::span_image_resample_rgba_affine<img_accessor_type> span_gen_type;
+ typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
+ span_gen_type sg(ia, interpolator, filter);
+ renderer_type ri(rb, sa, sg);
+ agg::render_scanlines(ras, sl, ri);
+ }
+ else
+ {
+ typedef agg::span_image_filter_rgba_2x2<img_accessor_type, interpolator_type> span_gen_type;
+ typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
+ span_gen_type sg(ia, interpolator, filter);
+ renderer_type ri(rb, sa, sg);
+ agg::render_scanlines(ras, sl, ri);
+ }
}
break;
case BILINEAR:
@@ -464,11 +475,22 @@
case LANCZOS: filter.calculate(agg::image_filter_lanczos(radius), norm); break;
case BLACKMAN: filter.calculate(agg::image_filter_blackman(radius), norm); break;
}
- typedef agg::span_image_filter_rgba<img_accessor_type, interpolator_type> span_gen_type;
- typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
- span_gen_type sg(ia, interpolator, filter);
- renderer_type ri(rb, sa, sg);
- agg::render_scanlines(ras, sl, ri);
+ if (resample)
+ {
+ typedef agg::span_image_resample_rgba_affine<img_accessor_type> span_gen_type;
+ typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
+ span_gen_type sg(ia, interpolator, filter);
+ renderer_type ri(rb, sa, sg);
+ agg::render_scanlines(ras, sl, ri);
+ }
+ else
+ {
+ typedef agg::span_image_filter_rgba<img_accessor_type, interpolator_type> span_gen_type;
+ typedef agg::renderer_scanline_aa<renderer_base, span_alloc_type, span_gen_type> renderer_type;
+ span_gen_type sg(ia, interpolator, filter);
+ renderer_type ri(rb, sa, sg);
+ agg::render_scanlines(ras, sl, ri);
+ }
}
break;
@@ -530,6 +552,20 @@
}
+char Image::get_resample__doc__[] =
+"get_resample()\n"
+"\n"
+"Get the resample flag."
+;
+
+Py::Object
+Image::get_resample(const Py::Tuple& args) {
+ _VERBOSE("Image::get_resample");
+
+ args.verify_length(0);
+ return Py::Int((int)resample);
+}
+
char Image::get_size_out__doc__[] =
"numrows, numcols = get_size()\n"
"\n"
@@ -593,6 +629,21 @@
}
+char Image::set_resample__doc__[] =
+"set_resample(boolean)\n"
+"\n"
+"Set the resample flag."
+;
+
+Py::Object
+Image::set_resample(const Py::Tuple& args) {
+ _VERBOSE("Image::set_resample");
+ args.verify_length(1);
+ int flag = Py::Int(args[0]);
+ resample = (bool)flag;
+ return Py::Object();
+}
+
static void write_png_data(png_structp png_ptr, png_bytep data, png_size_t length) {
PyObject* py_file_obj = (PyObject*)png_get_io_ptr(png_ptr);
PyObject* write_method = PyObject_GetAttrString(py_file_obj, "write");
@@ -752,12 +803,14 @@
add_varargs_method( "buffer_rgba", &Image::buffer_rgba, Image::buffer_rgba__doc__);
add_varargs_method( "get_aspect", &Image::get_aspect, Image::get_aspect__doc__);
add_varargs_method( "get_interpolation", &Image::get_interpolation, Image::get_interpolation__doc__);
+ add_varargs_method( "get_resample", &Image::get_resample, Image::get_resample__doc__);
add_varargs_method( "get_size", &Image::get_size, Image::get_size__doc__);
add_varargs_method( "get_size_out", &Image::get_size_out, Image::get_size_out__doc__);
add_varargs_method( "reset_matrix", &Image::reset_matrix, Image::reset_matrix__doc__);
add_varargs_method( "get_matrix", &Image::get_matrix, Image::get_matrix__doc__);
add_keyword_method( "resize", &Image::resize, Image::resize__doc__);
add_varargs_method( "set_interpolation", &Image::set_interpolation, Image::set_interpolation__doc__);
+ add_varargs_method( "set_resample", &Image::set_resample, Image::set_resample__doc__);
add_varargs_method( "set_aspect", &Image::set_aspect, Image::set_aspect__doc__);
add_varargs_method( "write_png", &Image::write_png, Image::write_png__doc__);
add_varargs_method( "set_bg", &Image::set_bg, Image::set_bg__doc__);
Modified: trunk/matplotlib/src/_image.h
===================================================================
--- trunk/matplotlib/src/_image.h 2008-06-09 16:48:50 UTC (rev 5432)
+++ trunk/matplotlib/src/_image.h 2008-06-09 17:00:08 UTC (rev 5433)
@@ -42,6 +42,8 @@
Py::Object set_bg(const Py::Tuple& args);
Py::Object flipud_out(const Py::Tuple& args);
Py::Object flipud_in(const Py::Tuple& args);
+ Py::Object set_resample(const Py::Tuple& args);
+ Py::Object get_resample(const Py::Tuple& args);
std::pair<agg::int8u*, bool> _get_output_buffer();
@@ -78,6 +80,7 @@
unsigned interpolation, aspect;
agg::rgba bg;
+ bool resample;
private:
Py::Dict __dict__;
agg::trans_affine srcMatrix, imageMatrix;
@@ -101,6 +104,8 @@
static char set_bg__doc__[];
static char flipud_out__doc__[];
static char flipud_in__doc__[];
+ static char get_resample__doc__[];
+ static char set_resample__doc__[];
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|