You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(115) |
Aug
(120) |
Sep
(137) |
Oct
(170) |
Nov
(461) |
Dec
(263) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(120) |
Feb
(74) |
Mar
(35) |
Apr
(74) |
May
(245) |
Jun
(356) |
Jul
(240) |
Aug
(115) |
Sep
(78) |
Oct
(225) |
Nov
(98) |
Dec
(271) |
| 2009 |
Jan
(132) |
Feb
(84) |
Mar
(74) |
Apr
(56) |
May
(90) |
Jun
(79) |
Jul
(83) |
Aug
(296) |
Sep
(214) |
Oct
(76) |
Nov
(82) |
Dec
(66) |
| 2010 |
Jan
(46) |
Feb
(58) |
Mar
(51) |
Apr
(77) |
May
(58) |
Jun
(126) |
Jul
(128) |
Aug
(64) |
Sep
(50) |
Oct
(44) |
Nov
(48) |
Dec
(54) |
| 2011 |
Jan
(68) |
Feb
(52) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <ef...@us...> - 2009-01-07 22:42:05
|
Revision: 6762
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6762&view=rev
Author: efiring
Date: 2009-01-07 22:42:01 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
Merged 6754, 6761 from v0_98_5_maint
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/__init__.py
Modified: trunk/matplotlib/lib/matplotlib/__init__.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/__init__.py 2009-01-07 22:30:41 UTC (rev 6761)
+++ trunk/matplotlib/lib/matplotlib/__init__.py 2009-01-07 22:42:01 UTC (rev 6762)
@@ -679,7 +679,7 @@
"%s"\n\t%s' % (val, cnt, line, fname, msg))
elif key in _deprecated_ignore_map:
warnings.warn('%s is deprecated. Update your matplotlibrc to use %s instead.'% (key, _deprecated_ignore_map[key]))
-
+
else:
print >> sys.stderr, """
Bad key "%s" on line %d in
@@ -838,9 +838,12 @@
else:
be_parts = arg.split('.')
name = validate_backend(be_parts[0])
+ if len(be_parts) > 1:
+ if name == 'cairo':
+ rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
+ else:
+ raise ValueError('Only cairo backend has a format option')
rcParams['backend'] = name
- if name == 'cairo' and len(be_parts) > 1:
- rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
def get_backend():
"Returns the current backend"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ef...@us...> - 2009-01-07 22:30:45
|
Revision: 6761
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6761&view=rev
Author: efiring
Date: 2009-01-07 22:30:41 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
Fix validation error in matplotlib.use()
Modified Paths:
--------------
branches/v0_98_5_maint/lib/matplotlib/__init__.py
Modified: branches/v0_98_5_maint/lib/matplotlib/__init__.py
===================================================================
--- branches/v0_98_5_maint/lib/matplotlib/__init__.py 2009-01-07 18:09:46 UTC (rev 6760)
+++ branches/v0_98_5_maint/lib/matplotlib/__init__.py 2009-01-07 22:30:41 UTC (rev 6761)
@@ -679,7 +679,7 @@
"%s"\n\t%s' % (val, cnt, line, fname, msg))
elif key in _deprecated_ignore_map:
warnings.warn('%s is deprecated. Update your matplotlibrc to use %s instead.'% (key, _deprecated_ignore_map[key]))
-
+
else:
print >> sys.stderr, """
Bad key "%s" on line %d in
@@ -838,9 +838,12 @@
else:
be_parts = arg.split('.')
name = validate_backend(be_parts[0])
+ if len(be_parts) > 1:
+ if name == 'cairo':
+ rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
+ else:
+ raise ValueError('Only cairo backend has a format option')
rcParams['backend'] = name
- if name == 'cairo' and len(be_parts) > 1:
- rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
def get_backend():
"Returns the current backend"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-07 18:09:51
|
Revision: 6760
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6760&view=rev
Author: mdboom
Date: 2009-01-07 18:09:46 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
Upgrade CXX to 5.4.2
Modified Paths:
--------------
trunk/matplotlib/CXX/Config.hxx
trunk/matplotlib/CXX/Extensions.hxx
trunk/matplotlib/CXX/IndirectPythonInterface.cxx
trunk/matplotlib/CXX/IndirectPythonInterface.hxx
trunk/matplotlib/CXX/Objects.hxx
trunk/matplotlib/CXX/Version.hxx
trunk/matplotlib/CXX/WrapPython.h
trunk/matplotlib/CXX/cxx_extensions.cxx
Modified: trunk/matplotlib/CXX/Config.hxx
===================================================================
--- trunk/matplotlib/CXX/Config.hxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/Config.hxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -115,4 +115,20 @@
typedef int Py_ssize_t;
#endif
+// hash_map container usage selection
+// 1) if PYCXX_USING_STD_MAP is defined PyCXX will be using std::map<> container
+// implementation only.
+// 2) if compilers are used other than MS Visual Studio (7.1+) or GCC 3.x
+// STANDARD_LIBRARY_HAS_HASH_MAP must be defined before compilation to
+// make PyCXX using hash_map container.
+#if !defined( PYCXX_USING_STD_MAP )
+ #if defined( _MSC_VER ) || defined( __INTEL_COMPILER ) || defined ( __ICC ) || (defined( __GNUC__ ) && ( __GNUC__ > 3 ))
+ # define PYCXX_USING_HASH_MAP
+ #else
+ # if defined( STANDARD_LIBRARY_HAS_HASH_MAP ) && !defined( PYCXX_USING_HASH_MAP )
+ # define PYCXX_USING_HASH_MAP
+ # endif
+ #endif
+#endif
+
#endif // __PyCXX_config_hh__
Modified: trunk/matplotlib/CXX/Extensions.hxx
===================================================================
--- trunk/matplotlib/CXX/Extensions.hxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/Extensions.hxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -56,12 +56,112 @@
}
#include <vector>
+
+// std::map / hash_map selection and declarations ----------------------------
+#if !defined( PYCXX_USING_HASH_MAP )
+
#include <map>
+#else
+
+#if defined( __GNUC__) && !defined( _STLPORT_VERSION )
+ #include <ext/hash_map>
+#else
+ #include <hash_map>
+#endif
+#if defined( _STLPORT_VERSION )
+ #define __PYCXX_HASHMAP_NAMESPACE std
+ using namespace std;
+#elif defined ( _MSC_VER ) && !defined( __INTEL_COMPILER ) && !defined( __ICC ) && !defined( __ICL ) && !defined( __ECC )
+ #define __PYCXX_HASHMAP_NAMESPACE stdext
+ using namespace stdext;
+#elif defined( __INTEL_COMPILER ) || defined( __ICC ) || defined( __ICL ) || defined( __ECC )
+ #define __PYCXX_HASHMAP_NAMESPACE stdext
+ using namespace stdext;
+#elif defined( __GNUC__ )
+ #define __PYCXX_HASHMAP_NAMESPACE __gnu_cxx
+ using namespace __gnu_cxx;
+#else
+ #define __PYCXX_HASHMAP_NAMESPACE std
+ using namespace std;
+#endif
+
+class __pycxx_str_hash_func
+{
+public:
+ enum
+ {
+ // parameters for hash table
+ bucket_size = 4, // 0 < bucket_size
+ min_buckets = 8 // min_buckets = 2 ^^ N, 0 < N
+ };
+
+ // http://www.azillionmonkeys.com/qed/hash.html
+ size_t operator()( const std::string &str ) const
+ {
+ const unsigned char * data = reinterpret_cast<const unsigned char *>( str.c_str() );
+ int len = (int)str.length();
+ unsigned int hash = len;
+ unsigned int tmp;
+ int rem;
+
+ if (len <= 0 || data == NULL)
+ return 0;
+
+ rem = len & 3;
+ len >>= 2;
+
+ /* Main loop */
+ for (;len > 0; len--)
+ {
+ hash += (data[1] << 8) | data[0];
+ tmp = (((data[3] << 8) | data[2]) << 11) ^ hash;
+ hash = (hash << 16) ^ tmp;
+ data += 2*sizeof (unsigned short);
+ hash += hash >> 11;
+ }
+
+ /* Handle end cases */
+ switch (rem)
+ {
+ case 3: hash += (data[1] << 8) | data[0];
+ hash ^= hash << 16;
+ hash ^= data[sizeof (unsigned short)] << 18;
+ hash += hash >> 11;
+ break;
+ case 2: hash += (data[1] << 8) | data[0];
+ hash ^= hash << 11;
+ hash += hash >> 17;
+ break;
+ case 1: hash += *data;
+ hash ^= hash << 10;
+ hash += hash >> 1;
+ }
+
+ /* Force "avalanching" of final 127 bits */
+ hash ^= hash << 3;
+ hash += hash >> 5;
+ hash ^= hash << 4;
+ hash += hash >> 17;
+ hash ^= hash << 25;
+ hash += hash >> 6;
+
+ return hash;
+ }
+
+ bool operator()(const std::string &str_1, const std::string &str_2) const
+ {
+ // test if str_1 ordered before str_2
+ return str_1 < str_2;
+ }
+};
+#endif // PYCXX_USING_HASH_MAP
+// ----------------------------------------------------------------------
+
namespace Py
{
class ExtensionModuleBase;
-
+
// Make an Exception Type for use in raising custom exceptions
class ExtensionExceptionType : public Object
{
@@ -74,44 +174,44 @@
void init( ExtensionModuleBase &module, const std::string& name );
};
-
- class MethodTable
+
+ class MethodTable
{
public:
MethodTable();
virtual ~MethodTable();
-
+
void add(const char* method_name, PyCFunction f, const char* doc="", int flag=1);
PyMethodDef* table();
-
+
protected:
std::vector<PyMethodDef> t; // accumulator of PyMethodDef's
PyMethodDef *mt; // Actual method table produced when full
-
+
static PyMethodDef method (const char* method_name, PyCFunction f, int flags = 1, const char* doc="");
-
+
private:
//
// prevent the compiler generating these unwanted functions
//
MethodTable(const MethodTable& m); //unimplemented
void operator=(const MethodTable& m); //unimplemented
-
+
}; // end class MethodTable
-
+
extern "C"
{
typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args );
typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict );
};
-
+
template<class T>
class MethodDefExt : public PyMethodDef
{
public:
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
-
+
MethodDefExt
(
const char *_name,
@@ -124,11 +224,11 @@
ext_meth_def.ml_meth = _handler;
ext_meth_def.ml_flags = METH_VARARGS;
ext_meth_def.ml_doc = const_cast<char *>(_doc);
-
+
ext_varargs_function = _function;
ext_keyword_function = NULL;
}
-
+
MethodDefExt
(
const char *_name,
@@ -141,57 +241,57 @@
ext_meth_def.ml_meth = method_varargs_call_handler_t( _handler );
ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS;
ext_meth_def.ml_doc = const_cast<char *>(_doc);
-
+
ext_varargs_function = NULL;
ext_keyword_function = _function;
}
-
+
~MethodDefExt()
{}
-
+
PyMethodDef ext_meth_def;
- method_varargs_function_t ext_varargs_function;
- method_keyword_function_t ext_keyword_function;
+ method_varargs_function_t ext_varargs_function;
+ method_keyword_function_t ext_keyword_function;
};
-
+
class ExtensionModuleBase
{
public:
ExtensionModuleBase( const char *name );
virtual ~ExtensionModuleBase();
-
+
Module module(void) const; // only valid after initialize() has been called
Dict moduleDictionary(void) const; // only valid after initialize() has been called
-
+
virtual Object invoke_method_keyword( const std::string &_name, const Tuple &_args, const Dict &_keywords ) = 0;
virtual Object invoke_method_varargs( const std::string &_name, const Tuple &_args ) = 0;
-
+
const std::string &name() const;
const std::string &fullName() const;
-
+
protected:
// Initialize the module
void initialize( const char *module_doc );
-
+
const std::string module_name;
const std::string full_module_name;
MethodTable method_table;
-
+
private:
-
+
//
// prevent the compiler generating these unwanted functions
//
ExtensionModuleBase( const ExtensionModuleBase & ); //unimplemented
void operator=( const ExtensionModuleBase & ); //unimplemented
-
+
};
-
+
extern "C" PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords );
extern "C" PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args );
extern "C" void do_not_dealloc( void * );
-
-
+
+
template<TEMPLATE_TYPENAME T>
class ExtensionModule : public ExtensionModuleBase
{
@@ -201,16 +301,21 @@
{}
virtual ~ExtensionModule()
{}
-
+
protected:
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
+
+#if defined( PYCXX_USING_HASH_MAP )
+ typedef __PYCXX_HASHMAP_NAMESPACE::hash_map<std::string, MethodDefExt<T> *, __pycxx_str_hash_func> method_map_t;
+#else
typedef std::map<std::string,MethodDefExt<T> *> method_map_t;
-
+#endif
+
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
{
method_map_t &mm = methods();
-
+
MethodDefExt<T> *method_definition = new MethodDefExt<T>
(
name,
@@ -218,14 +323,14 @@
method_varargs_call_handler,
doc
);
-
+
mm[std::string( name )] = method_definition;
}
-
+
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
{
method_map_t &mm = methods();
-
+
MethodDefExt<T> *method_definition = new MethodDefExt<T>
(
name,
@@ -233,7 +338,7 @@
method_keyword_call_handler,
doc
);
-
+
mm[std::string( name )] = method_definition;
}
@@ -241,46 +346,46 @@
{
ExtensionModuleBase::initialize( module_doc );
Dict dict( moduleDictionary() );
-
+
//
// put each of the methods into the modules dictionary
// so that we get called back at the function in T.
//
method_map_t &mm = methods();
- EXPLICIT_TYPENAME method_map_t::iterator i;
-
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+
for( i=mm.begin(); i != mm.end(); ++i )
{
MethodDefExt<T> *method_definition = (*i).second;
-
+
static PyObject *self = PyCObject_FromVoidPtr( this, do_not_dealloc );
-
+
Tuple args( 2 );
args[0] = Object( self );
args[1] = String( (*i).first );
-
+
PyObject *func = PyCFunction_New
(
&method_definition->ext_meth_def,
new_reference_to( args )
);
-
+
dict[ (*i).first ] = Object( func );
}
}
-
+
protected: // Tom Malcolmson reports that derived classes need access to these
-
+
static method_map_t &methods(void)
{
static method_map_t *map_of_methods = NULL;
if( map_of_methods == NULL )
map_of_methods = new method_map_t;
-
+
return *map_of_methods;
}
-
-
+
+
// this invoke function must be called from within a try catch block
virtual Object invoke_method_keyword( const std::string &name, const Tuple &args, const Dict &keywords )
{
@@ -292,13 +397,13 @@
error_msg += name;
throw RuntimeError( error_msg );
}
-
+
// cast up to the derived class
T *self = static_cast<T *>(this);
-
+
return (self->*meth_def->ext_keyword_function)( args, keywords );
}
-
+
// this invoke function must be called from within a try catch block
virtual Object invoke_method_varargs( const std::string &name, const Tuple &args )
{
@@ -310,13 +415,13 @@
error_msg += name;
throw RuntimeError( error_msg );
}
-
+
// cast up to the derived class
T *self = static_cast<T *>(this);
-
+
return (self->*meth_def->ext_varargs_function)( args );
}
-
+
private:
//
// prevent the compiler generating these unwanted functions
@@ -324,17 +429,17 @@
ExtensionModule( const ExtensionModule<T> & ); //unimplemented
void operator=( const ExtensionModule<T> & ); //unimplemented
};
-
-
+
+
class PythonType
{
public:
- // if you define one sequence method you must define
+ // if you define one sequence method you must define
// all of them except the assigns
-
+
PythonType (size_t base_size, int itemsize, const char *default_name );
virtual ~PythonType ();
-
+
const char *getName () const;
const char *getDoc () const;
@@ -342,73 +447,76 @@
PythonType & name (const char* nam);
PythonType & doc (const char* d);
PythonType & dealloc(void (*f)(PyObject*));
-
+
PythonType & supportPrint(void);
PythonType & supportGetattr(void);
PythonType & supportSetattr(void);
PythonType & supportGetattro(void);
PythonType & supportSetattro(void);
PythonType & supportCompare(void);
+#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
+ PythonType & supportRichCompare(void);
+#endif
PythonType & supportRepr(void);
PythonType & supportStr(void);
PythonType & supportHash(void);
PythonType & supportCall(void);
PythonType & supportIter(void);
-
+
PythonType & supportSequenceType(void);
PythonType & supportMappingType(void);
PythonType & supportNumberType(void);
PythonType & supportBufferType(void);
-
+
protected:
PyTypeObject *table;
PySequenceMethods *sequence_table;
PyMappingMethods *mapping_table;
PyNumberMethods *number_table;
PyBufferProcs *buffer_table;
-
+
void init_sequence();
void init_mapping();
void init_number();
void init_buffer();
-
+
private:
//
// prevent the compiler generating these unwanted functions
//
PythonType (const PythonType& tb); // unimplemented
void operator=(const PythonType& t); // unimplemented
-
+
}; // end of PythonType
-
-
-
+
+
+
// Class PythonExtension is what you inherit from to create
// a new Python extension type. You give your class itself
// as the template paramter.
-
+
// There are two ways that extension objects can get destroyed.
// 1. Their reference count goes to zero
// 2. Someone does an explicit delete on a pointer.
- // In (1) the problem is to get the destructor called
+ // In (1) the problem is to get the destructor called
// We register a special deallocator in the Python type object
// (see behaviors()) to do this.
// In (2) there is no problem, the dtor gets called.
-
- // PythonExtension does not use the usual Python heap allocator,
+
+ // PythonExtension does not use the usual Python heap allocator,
// instead using new/delete. We do the setting of the type object
- // and reference count, usually done by PyObject_New, in the
+ // and reference count, usually done by PyObject_New, in the
// base class ctor.
-
+
// This special deallocator does a delete on the pointer.
-
-
+
+
class PythonExtensionBase : public PyObject
{
public:
PythonExtensionBase();
virtual ~PythonExtensionBase();
-
+
public:
virtual int print( FILE *, int );
virtual Object getattr( const char * ) = 0;
@@ -416,13 +524,14 @@
virtual Object getattro( const Object & );
virtual int setattro( const Object &, const Object & );
virtual int compare( const Object & );
+ virtual Object rich_compare( const Object &, int op );
virtual Object repr();
virtual Object str();
virtual long hash();
virtual Object call( const Object &, const Object & );
virtual Object iter();
virtual PyObject* iternext();
-
+
// Sequence methods
virtual int sequence_length();
virtual Object sequence_concat( const Object & );
@@ -431,12 +540,12 @@
virtual Object sequence_slice( Py_ssize_t, Py_ssize_t );
virtual int sequence_ass_item( Py_ssize_t, const Object & );
virtual int sequence_ass_slice( Py_ssize_t, Py_ssize_t, const Object & );
-
+
// Mapping
virtual int mapping_length();
virtual Object mapping_subscript( const Object & );
virtual int mapping_ass_subscript( const Object &, const Object & );
-
+
// Number
virtual int number_nonzero();
virtual Object number_negative();
@@ -460,38 +569,38 @@
virtual Object number_xor( const Object & );
virtual Object number_or( const Object & );
virtual Object number_power( const Object &, const Object & );
-
+
// Buffer
virtual Py_ssize_t buffer_getreadbuffer( Py_ssize_t, void** );
virtual Py_ssize_t buffer_getwritebuffer( Py_ssize_t, void** );
virtual Py_ssize_t buffer_getsegcount( Py_ssize_t* );
-
+
private:
void missing_method( void );
static PyObject *method_call_handler( PyObject *self, PyObject *args );
};
-
+
template<TEMPLATE_TYPENAME T>
- class PythonExtension: public PythonExtensionBase
+ class PythonExtension: public PythonExtensionBase
{
public:
- static PyTypeObject* type_object()
+ static PyTypeObject* type_object()
{
return behaviors().type_object();
}
-
+
static int check( PyObject *p )
{
// is p like me?
return p->ob_type == type_object();
}
-
+
static int check( const Object& ob )
{
return check( ob.ptr());
}
-
-
+
+
//
// every object needs getattr implemented
// to support methods
@@ -500,7 +609,7 @@
{
return getattr_methods( name );
}
-
+
protected:
explicit PythonExtension()
: PythonExtensionBase()
@@ -511,18 +620,18 @@
ob_refcnt = 1;
ob_type = type_object();
#endif
-
+
// every object must support getattr
behaviors().supportGetattr();
}
-
+
virtual ~PythonExtension()
- {}
-
+ {}
+
static PythonType &behaviors()
{
static PythonType* p;
- if( p == NULL )
+ if( p == NULL )
{
#if defined( _CPPRTTI ) || defined(__GNUG__)
const char *default_name = (typeid ( T )).name();
@@ -532,15 +641,20 @@
p = new PythonType( sizeof( T ), 0, default_name );
p->dealloc( extension_object_deallocator );
}
-
+
return *p;
}
-
-
+
+
typedef Object (T::*method_varargs_function_t)( const Tuple &args );
typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
+
+#if defined( PYCXX_USING_HASH_MAP )
+ typedef __PYCXX_HASHMAP_NAMESPACE::hash_map<std::string, MethodDefExt<T> *, __pycxx_str_hash_func> method_map_t;
+#else
typedef std::map<std::string,MethodDefExt<T> *> method_map_t;
-
+#endif
+
// support the default attributes, __name__, __doc__ and methods
virtual Object getattr_default( const char *_name )
{
@@ -576,39 +690,48 @@
virtual Object getattr_methods( const char *_name )
{
std::string name( _name );
-
+
method_map_t &mm = methods();
-
+
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+
if( name == "__methods__" )
{
List methods;
-
- for( EXPLICIT_TYPENAME method_map_t::iterator i = mm.begin(); i != mm.end(); ++i )
+
+ for( i = mm.begin(); i != mm.end(); ++i )
methods.append( String( (*i).first ) );
-
+
return methods;
}
-
- // see if name exists
- if( mm.find( name ) == mm.end() )
+
+ // see if name exists and get entry with method
+ i = mm.find( name );
+ if( i == mm.end() )
throw AttributeError( name );
-
+
Tuple self( 2 );
-
+
self[0] = Object( this );
self[1] = String( name );
-
- MethodDefExt<T> *method_definition = mm[ name ];
-
+
+ MethodDefExt<T> *method_definition = i->second;
+
PyObject *func = PyCFunction_New( &method_definition->ext_meth_def, self.ptr() );
-
+
return Object(func, true);
}
-
+
static void add_varargs_method( const char *name, method_varargs_function_t function, const char *doc="" )
{
method_map_t &mm = methods();
-
+
+ // check that all methods added are unique
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+ i = mm.find( name );
+ if( i != mm.end() )
+ throw AttributeError( name );
+
MethodDefExt<T> *method_definition = new MethodDefExt<T>
(
name,
@@ -616,14 +739,20 @@
method_varargs_call_handler,
doc
);
-
+
mm[std::string( name )] = method_definition;
}
-
+
static void add_keyword_method( const char *name, method_keyword_function_t function, const char *doc="" )
{
method_map_t &mm = methods();
-
+
+ // check that all methods added are unique
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+ i = mm.find( name );
+ if( i != mm.end() )
+ throw AttributeError( name );
+
MethodDefExt<T> *method_definition = new MethodDefExt<T>
(
name,
@@ -631,45 +760,49 @@
method_keyword_call_handler,
doc
);
-
+
mm[std::string( name )] = method_definition;
}
-
+
private:
static method_map_t &methods(void)
{
static method_map_t *map_of_methods = NULL;
if( map_of_methods == NULL )
map_of_methods = new method_map_t;
-
+
return *map_of_methods;
}
-
+
static PyObject *method_keyword_call_handler( PyObject *_self_and_name_tuple, PyObject *_args, PyObject *_keywords )
{
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
-
+
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
T *self = static_cast<T *>( self_in_cobject );
-
+
String name( self_and_name_tuple[1] );
-
+
method_map_t &mm = methods();
- MethodDefExt<T> *meth_def = mm[ name ];
- if( meth_def == NULL )
+
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+ i = mm.find( name );
+ if( i == mm.end() )
return 0;
-
+
+ MethodDefExt<T> *meth_def = i->second;
+
Tuple args( _args );
// _keywords may be NULL so be careful about the way the dict is created
Dict keywords;
if( _keywords != NULL )
keywords = Dict( _keywords );
-
+
Object result( (self->*meth_def->ext_keyword_function)( args, keywords ) );
-
+
return new_reference_to( result.ptr() );
}
catch( Exception & )
@@ -677,27 +810,31 @@
return 0;
}
}
-
+
static PyObject *method_varargs_call_handler( PyObject *_self_and_name_tuple, PyObject *_args )
{
try
{
Tuple self_and_name_tuple( _self_and_name_tuple );
-
+
PyObject *self_in_cobject = self_and_name_tuple[0].ptr();
T *self = static_cast<T *>( self_in_cobject );
-
+
String name( self_and_name_tuple[1] );
-
+
method_map_t &mm = methods();
- MethodDefExt<T> *meth_def = mm[ name ];
- if( meth_def == NULL )
+
+ EXPLICIT_TYPENAME method_map_t::const_iterator i;
+ i = mm.find( name );
+ if( i == mm.end() )
return 0;
-
+
+ MethodDefExt<T> *meth_def = i->second;
+
Tuple args( _args );
-
+
Object result;
-
+
// TMM: 7Jun'01 - Adding try & catch in case of STL debug-mode exceptions.
#ifdef _STLP_DEBUG
try
@@ -712,7 +849,7 @@
#else
result = (self->*meth_def->ext_varargs_function)( args );
#endif // _STLP_DEBUG
-
+
return new_reference_to( result.ptr() );
}
catch( Exception & )
@@ -720,19 +857,19 @@
return 0;
}
}
-
+
static void extension_object_deallocator ( PyObject* t )
{
delete (T *)( t );
}
-
+
//
// prevent the compiler generating these unwanted functions
//
explicit PythonExtension( const PythonExtension<T>& other );
void operator=( const PythonExtension<T>& rhs );
};
-
+
//
// ExtensionObject<T> is an Object that will accept only T's.
//
@@ -740,30 +877,30 @@
class ExtensionObject: public Object
{
public:
-
+
explicit ExtensionObject ( PyObject *pyob )
: Object( pyob )
{
validate();
}
-
+
ExtensionObject( const ExtensionObject<T>& other )
: Object( *other )
{
validate();
}
-
+
ExtensionObject( const Object& other )
: Object( *other )
{
validate();
}
-
+
ExtensionObject& operator= ( const Object& rhs )
{
return (*this = *rhs );
}
-
+
ExtensionObject& operator= ( PyObject* rhsp )
{
if( ptr() == rhsp )
@@ -771,12 +908,12 @@
set( rhsp );
return *this;
}
-
+
virtual bool accepts ( PyObject *pyob ) const
{
return ( pyob && T::check( pyob ));
- }
-
+ }
+
//
// Obtain a pointer to the PythonExtension object
//
@@ -785,7 +922,7 @@
return static_cast<T *>( ptr() );
}
};
-
+
} // Namespace Py
// End of CXX_Extensions.h
#endif
Modified: trunk/matplotlib/CXX/IndirectPythonInterface.cxx
===================================================================
--- trunk/matplotlib/CXX/IndirectPythonInterface.cxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/IndirectPythonInterface.cxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -49,6 +49,7 @@
bool _Float_Check( PyObject *op ) { return (op)->ob_type == _Float_Type(); }
bool _Function_Check( PyObject *op ) { return (op)->ob_type == _Function_Type(); }
bool _Instance_Check( PyObject *op ) { return (op)->ob_type == _Instance_Type(); }
+bool _Boolean_Check( PyObject *op ) { return (op)->ob_type == _Bool_Type(); }
bool _Int_Check( PyObject *op ) { return (op)->ob_type == _Int_Type(); }
bool _List_Check( PyObject *o ) { return o->ob_type == _List_Type(); }
bool _Long_Check( PyObject *op ) { return (op)->ob_type == _Long_Type(); }
@@ -116,6 +117,9 @@
static PyObject *ptr__PyNone = NULL;
+static PyObject *ptr__PyFalse = NULL;
+static PyObject *ptr__PyTrue = NULL;
+
static PyTypeObject *ptr__Buffer_Type = NULL;
static PyTypeObject *ptr__CFunction_Type = NULL;
static PyTypeObject *ptr__Class_Type = NULL;
@@ -300,6 +304,9 @@
#endif
ptr__PyNone = GetPyObject_As_PyObjectPointer( "_Py_NoneStruct" );
+ ptr__PyFalse = GetPyObject_As_PyObjectPointer( "_Py_ZeroStruct" );
+ ptr__PyTrue = GetPyObject_As_PyObjectPointer( "_Py_TrueStruct" );
+
ptr__Buffer_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyBuffer_Type" );
ptr__CFunction_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyCFunction_Type" );
ptr__Class_Type = GetPyTypeObject_As_PyTypeObjectPointer( "PyClass_Type" );
@@ -385,6 +392,8 @@
//
PyObject * _None() { return ptr__PyNone; }
+PyObject * _False() { return ptr__PyFalse; }
+PyObject * _True() { return ptr__PyTrue; }
PyTypeObject * _Buffer_Type() { return ptr__Buffer_Type; }
PyTypeObject * _CFunction_Type(){ return ptr__CFunction_Type; }
@@ -396,6 +405,7 @@
PyTypeObject * _Float_Type() { return ptr__Float_Type; }
PyTypeObject * _Function_Type() { return ptr__Function_Type; }
PyTypeObject * _Instance_Type() { return ptr__Instance_Type; }
+PyTypeObject * _Bool_Type() { return ptr__Bool_Type; }
PyTypeObject * _Int_Type() { return ptr__Int_Type; }
PyTypeObject * _List_Type() { return ptr__List_Type; }
PyTypeObject * _Long_Type() { return ptr__Long_Type; }
@@ -526,6 +536,9 @@
//
PyObject * _None() { return &::_Py_NoneStruct; }
+PyObject * _False() { return Py_False; }
+PyObject * _True() { return Py_True; }
+
PyTypeObject * _Buffer_Type() { return &PyBuffer_Type; }
PyTypeObject * _CFunction_Type() { return &PyCFunction_Type; }
PyTypeObject * _Class_Type() { return &PyClass_Type; }
@@ -536,6 +549,7 @@
PyTypeObject * _Float_Type() { return &PyFloat_Type; }
PyTypeObject * _Function_Type() { return &PyFunction_Type; }
PyTypeObject * _Instance_Type() { return &PyInstance_Type; }
+PyTypeObject * _Bool_Type() { return &PyBool_Type; }
PyTypeObject * _Int_Type() { return &PyInt_Type; }
PyTypeObject * _List_Type() { return &PyList_Type; }
PyTypeObject * _Long_Type() { return &PyLong_Type; }
Modified: trunk/matplotlib/CXX/IndirectPythonInterface.hxx
===================================================================
--- trunk/matplotlib/CXX/IndirectPythonInterface.hxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/IndirectPythonInterface.hxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -92,6 +92,8 @@
//
PyObject * _None();
+PyObject * _False();
+PyObject * _True();
//
// Wrap Type variables as function calls
@@ -132,6 +134,9 @@
PyTypeObject * _Function_Type();
bool _Function_Check( PyObject *op );
+PyTypeObject * _Bool_Type();
+bool _Boolean_Check( PyObject *op );
+
PyTypeObject * _Int_Type();
bool _Int_Check( PyObject *op );
Modified: trunk/matplotlib/CXX/Objects.hxx
===================================================================
--- trunk/matplotlib/CXX/Objects.hxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/Objects.hxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -168,26 +168,7 @@
p = 0;
}
- void validate()
- {
- // release pointer if not the right type
- if (! accepts (p))
- {
- release ();
- if(PyErr_Occurred())
- { // Error message already set
- throw Exception();
- }
- // Better error message if RTTI available
-#if defined( _CPPRTTI ) || defined(__GNUG__)
- std::string s("CXX : Error creating object of type ");
- s += (typeid (*this)).name();
- throw TypeError (s);
-#else
- throw TypeError ("CXX: type error.");
-#endif
- }
- }
+ void validate();
public:
// Constructor acquires new ownership of pointer unless explicitly told not to.
@@ -315,7 +296,7 @@
bool isNone() const
{
- return p == Py_None;
+ return p == _None();
}
bool isCallable () const
@@ -397,18 +378,19 @@
// failed to link on Windows?
throw KeyError("delItem failed.");
}
- // Equality and comparison use PyObject_Compare
+ // Equality and comparison use PyObject_RichCompareBool
+
bool operator==(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_EQ);
if (PyErr_Occurred()) throw Exception();
- return k == 0;
+ return k != 0;
}
bool operator!=(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_NE);
if (PyErr_Occurred()) throw Exception();
return k != 0;
@@ -416,30 +398,30 @@
bool operator>=(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_GE);
if (PyErr_Occurred()) throw Exception();
- return k >= 0;
+ return k != 0;
}
bool operator<=(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_LE);
if (PyErr_Occurred()) throw Exception();
- return k <= 0;
+ return k != 0;
}
bool operator<(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_LT);
if (PyErr_Occurred()) throw Exception();
- return k < 0;
+ return k != 0;
}
bool operator>(const Object& o2) const
{
- int k = PyObject_Compare (p, *o2);
+ int k = PyObject_RichCompareBool (p, *o2, Py_GT);
if (PyErr_Occurred()) throw Exception();
- return k > 0;
+ return k != 0;
}
};
// End of class Object
@@ -463,6 +445,17 @@
return Object(Py::_None());
}
+ // Python special Boolean values
+ inline Object False()
+ {
+ return Object(Py::_False());
+ }
+
+ inline Object True()
+ {
+ return Object(Py::_True());
+ }
+
// TMM: 31May'01 - Added the #ifndef so I can exlude iostreams.
#ifndef CXX_NO_IOSTREAMS
std::ostream& operator<< (std::ostream& os, const Object& ob);
@@ -513,9 +506,68 @@
return Object(p, true);
}
+ // ===============================================
+ // class boolean
+ class Boolean: public Object
+ {
+ public:
+ // Constructor
+ Boolean (PyObject *pyob, bool owned = false): Object (pyob, owned)
+ {
+ validate();
+ }
+ Boolean (const Boolean& ob): Object(*ob)
+ {
+ validate();
+ }
+ // create from bool
+ Boolean (bool v=false)
+ {
+ set(PyBool_FromLong(v ? 1 : 0), true);
+ validate();
+ }
+ explicit Boolean (const Object& ob)
+ {
+ set(*ob, true);
+ validate();
+ }
+
+ // Assignment acquires new ownership of pointer
+
+ Boolean& operator= (const Object& rhs)
+ {
+ return (*this = *rhs);
+ }
+
+ Boolean& operator= (PyObject* rhsp)
+ {
+ if(ptr() == rhsp) return *this;
+ set (rhsp, true);
+ return *this;
+ }
+
+ // Membership
+ virtual bool accepts (PyObject *pyob) const
+ {
+ return pyob && Py::_Boolean_Check (pyob);
+ }
+
+ // convert to long
+ operator bool() const
+ {
+ return PyObject_IsTrue (ptr()) != 0;
+ }
+
+ Boolean& operator= (bool v)
+ {
+ set (PyBool_FromLong (v ? 1 : 0), true);
+ return *this;
+ }
+ };
+
// ===============================================
// class Int
class Int: public Object
@@ -538,19 +590,6 @@
validate();
}
-#ifdef HAVE_LONG_LONG
- // create from long long
- Int (PY_LONG_LONG v): Object(PyLong_FromLongLong(v), true)
- {
- validate();
- }
- // create from unsigned long long
- Int (unsigned PY_LONG_LONG v): Object(PyLong_FromUnsignedLongLong(v), true)
- {
- validate();
- }
-#endif
-
// create from int
Int (int v)
{
@@ -753,13 +792,13 @@
validate();
}
// create from long long
- explicit LongLong (long long v = 0L)
+ explicit LongLong (PY_LONG_LONG v = 0L)
: Object(PyLong_FromLongLong(v), true)
{
validate();
}
// create from unsigned long long
- explicit LongLong (unsigned long long v)
+ explicit LongLong (unsigned PY_LONG_LONG v)
: Object(PyLong_FromUnsignedLongLong(v), true)
{
validate();
@@ -778,7 +817,7 @@
}
// create from int
explicit LongLong (int v)
- : Object(PyLong_FromLongLong(static_cast<long long>(v)), true)
+ : Object(PyLong_FromLongLong(static_cast<PY_LONG_LONG>(v)), true)
{
validate();
}
@@ -809,12 +848,12 @@
return pyob && Py::_Long_Check (pyob);
}
// convert to long long
- operator long long() const
+ operator PY_LONG_LONG() const
{
return PyLong_AsLongLong (ptr());
}
// convert to unsigned long
- operator unsigned long long() const
+ operator unsigned PY_LONG_LONG() const
{
return PyLong_AsUnsignedLongLong (ptr());
}
@@ -839,13 +878,13 @@
return *this;
}
// assign from long long
- LongLong& operator= (long long v)
+ LongLong& operator= (PY_LONG_LONG v)
{
set(PyLong_FromLongLong (v), true);
return *this;
}
// assign from unsigned long long
- LongLong& operator= (unsigned long long v)
+ LongLong& operator= (unsigned PY_LONG_LONG v)
{
set(PyLong_FromUnsignedLongLong (v), true);
return *this;
@@ -1413,12 +1452,12 @@
bool eql (const iterator& other) const
{
- return (*seq == *other.seq) && (count == other.count);
+ return (seq->ptr() == other.seq->ptr()) && (count == other.count);
}
bool neq (const iterator& other) const
{
- return (*seq != *other.seq) || (count != other.count);
+ return (seq->ptr() != other.seq->ptr()) || (count != other.count);
}
bool lss (const iterator& other) const
@@ -1527,6 +1566,12 @@
const SeqBase<T>* seq;
sequence_index_type count;
+ private:
+ const_iterator (const SeqBase<T>* s, int where)
+ : seq( s )
+ , count( where )
+ {}
+
public:
~const_iterator ()
{}
@@ -1536,11 +1581,6 @@
, count( 0 )
{}
- const_iterator (const SeqBase<T>* s, int where)
- : seq( s )
- , count( where )
- {}
-
const_iterator(const const_iterator& other)
: seq( other.seq )
, count( other.count )
@@ -1571,12 +1611,12 @@
bool eql (const const_iterator& other) const
{
- return (*seq == *other.seq) && (count == other.count);
+ return (seq->ptr() == other.seq->ptr()) && (count == other.count);
}
bool neq (const const_iterator& other) const
{
- return (*seq != *other.seq) || (count != other.count);
+ return (seq->ptr() != other.seq->ptr()) || (count != other.count);
}
bool lss (const const_iterator& other) const
@@ -1662,7 +1702,7 @@
template <TEMPLATE_TYPENAME T> bool operator< (const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
template <TEMPLATE_TYPENAME T> bool operator> (const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
template <TEMPLATE_TYPENAME T> bool operator<=(const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
- template <TEMPLATE_TYPENAME T> bool operator>=(const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
+ template <TEMPLATE_TYPENAME T> bool operator>=(const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& left, const EXPLICIT_TYPENAME SeqBase<T>::const_iterator& right);
extern bool operator==(const Sequence::iterator& left, const Sequence::iterator& right);
@@ -1677,7 +1717,7 @@
extern bool operator< (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
extern bool operator> (const Sequence::const_iterator& left, const Sequence::const_iterator& right);
extern bool operator<=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
- extern bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
+ extern bool operator>=(const Sequence::const_iterator& left, const Sequence::const_iterator& right);
// ==================================================
// class Char
@@ -1979,7 +2019,7 @@
set(PyTuple_New (limit), true);
validate();
-
+
for(sequence_index_type i=0; i < limit; i++)
{
if(PyTuple_SetItem (ptr(), i, new_reference_to(s[i])) == -1)
@@ -2476,39 +2516,6 @@
return List(PyMapping_Items(ptr()), true);
}
- // iterators for MapBase<T>
- // Added by TMM: 2Jul'01 - NOT COMPLETED
- // There is still a bug. I decided to stop, before fixing the bug, because
- // this can't be halfway efficient until Python gets built-in iterators.
- // My current soln is to iterate over the map by getting a copy of its keys
- // and iterating over that. Not a good solution.
-
- // The iterator holds a MapBase<T>* rather than a MapBase<T> because that's
- // how the sequence iterator is implemented and it works. But it does seem
- // odd to me - we are iterating over the map object, not the reference.
-
-#if 0 // here is the test code with which I found the (still existing) bug
- typedef cxx::Dict d_t;
- d_t d;
- cxx::String s1("blah");
- cxx::String s2("gorf");
- d[ "one" ] = s1;
- d[ "two" ] = s1;
- d[ "three" ] = s2;
- d[ "four" ] = s2;
-
- d_t::iterator it;
- it = d.begin(); // this (using the assignment operator) is causing
- // a problem; if I just use the copy ctor it works fine.
- for( ; it != d.end(); ++it )
- {
- d_t::value_type vt( *it );
- cxx::String rs = vt.second.repr();
- std::string ls = rs.operator std::string();
- fprintf( stderr, "%s\n", ls );
- }
-#endif // 0
-
class iterator
{
// : public forward_iterator_parent( std::pair<const T,T> ) {
@@ -2523,8 +2530,15 @@
//
MapBase<T>* map;
List keys; // for iterating over the map
- List::iterator pos; // index into the keys
+ int pos; // index into the keys
+ private:
+ iterator( MapBase<T>* m, List k, int p )
+ : map( m )
+ , keys( k )
+ , pos( p )
+ {}
+
public:
~iterator ()
{}
@@ -2538,7 +2552,7 @@
iterator (MapBase<T>* m, bool end = false )
: map( m )
, keys( m->keys() )
- , pos( end ? keys.end() : keys.begin() )
+ , pos( end ? keys.length() : 0 )
{}
iterator (const iterator& other)
@@ -2549,7 +2563,7 @@
reference operator*()
{
- Object key = *pos;
+ Object key = keys[ pos ];
return std::make_pair(key, mapref<T>(*map,key));
}
@@ -2565,11 +2579,11 @@
bool eql(const iterator& right) const
{
- return *map == *right.map && pos == right.pos;
+ return map->ptr() == right.map->ptr() && pos == right.pos;
}
bool neq( const iterator& right ) const
{
- return *map != *right.map || pos != right.pos;
+ return map->ptr() != right.map->ptr() || pos != right.pos;
}
// pointer operator->() {
@@ -2619,8 +2633,15 @@
friend class MapBase<T>;
const MapBase<T>* map;
List keys; // for iterating over the map
- List::iterator pos; // index into the keys
+ int pos; // index into the keys
+ private:
+ const_iterator( MapBase<T>* m, List k, int p )
+ : map( m )
+ , keys( k )
+ , pos( p )
+ {}
+
public:
~const_iterator ()
{}
@@ -2631,10 +2652,10 @@
, pos()
{}
- const_iterator (const MapBase<T>* m, List k, List::iterator p )
+ const_iterator (MapBase<T>* m, bool end = false )
: map( m )
- , keys( k )
- , pos( p )
+ , keys( m->keys() )
+ , pos( end ? keys.length() : 0 )
{}
const_iterator(const const_iterator& other)
@@ -2645,20 +2666,20 @@
bool eql(const const_iterator& right) const
{
- return *map == *right.map && pos == right.pos;
+ return map->ptr() == right.map->ptr() && pos == right.pos;
}
+
bool neq( const const_iterator& right ) const
{
- return *map != *right.map || pos != right.pos;
+ return map->ptr() != right.map->ptr() || pos != right.pos;
}
+ const_reference operator*()
+ {
+ Object key = keys[ pos ];
+ return std::make_pair( key, mapref<T>( *map, key ) );
+ }
- // const_reference operator*() {
- // Object key = *pos;
- // return std::make_pair( key, map->[key] );
- // GCC < 3 barfes on this line at the '['.
- // }
-
const_iterator& operator=(const const_iterator& other)
{
if (this == &other) return *this;
@@ -2684,12 +2705,12 @@
const_iterator begin () const
{
- return const_iterator(this, 0);
+ return const_iterator(this);
}
const_iterator end () const
{
- return const_iterator(this, length());
+ return const_iterator(this, true);
}
}; // end of MapBase<T>
@@ -2717,7 +2738,7 @@
{
validate();
}
- Dict (const Dict& ob): Mapping(ob)
+ Dict (const Object& ob): Mapping(ob)
{
validate();
}
Modified: trunk/matplotlib/CXX/Version.hxx
===================================================================
--- trunk/matplotlib/CXX/Version.hxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/Version.hxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -40,7 +40,7 @@
#define PYCXX_VERSION_MAJOR 5
#define PYCXX_VERSION_MINOR 4
-#define PYCXX_VERSION_PATCH 0
+#define PYCXX_VERSION_PATCH 2
#define PYCXX_MAKEVERSION( major, minor, patch ) ((major<<16)|(minor<<8)|(patch))
#define PYCXX_VERSION PYCXX_MAKEVERSION( PYCXX_VERSION_MAJOR, PYCXX_VERSION_MINOR, PYCXX_VERSION_PATCH )
#endif
Modified: trunk/matplotlib/CXX/WrapPython.h
===================================================================
--- trunk/matplotlib/CXX/WrapPython.h 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/WrapPython.h 2009-01-07 18:09:46 UTC (rev 6760)
@@ -46,5 +46,4 @@
#include <sys/time.h>
#endif
-
#endif
Modified: trunk/matplotlib/CXX/cxx_extensions.cxx
===================================================================
--- trunk/matplotlib/CXX/cxx_extensions.cxx 2009-01-07 16:16:18 UTC (rev 6759)
+++ trunk/matplotlib/CXX/cxx_extensions.cxx 2009-01-07 18:09:46 UTC (rev 6760)
@@ -39,15 +39,50 @@
#include <assert.h>
-namespace Py
+namespace Py
{
+
+void Object::validate()
+{
+ // release pointer if not the right type
+ if( !accepts( p ) )
+ {
+#if defined( _CPPRTTI ) || defined( __GNUG__ )
+ std::string s( "PyCXX: Error creating object of type " );
+ s += (typeid( *this )).name();
+
+ if( p != 0 )
+ {
+ String from_repr = repr();
+ s += " from ";
+ s += from_repr.as_std_string();
+ }
+ else
+ {
+ s += " from (nil)";
+ }
+#endif
+ release();
+ if( PyErr_Occurred() )
+ { // Error message already set
+ throw Exception();
+ }
+ // Better error message if RTTI available
+#if defined( _CPPRTTI ) || defined( __GNUG__ )
+ throw TypeError( s );
+#else
+ throw TypeError( "PyCXX: type error." );
+#endif
+ }
+}
+
//================================================================================
//
// Implementation of MethodTable
//
//================================================================================
-PyMethodDef MethodTable::method( const char* method_name, PyCFunction f, int flags, const char* doc )
+PyMethodDef MethodTable::method( const char* method_name, PyCFunction f, int flags, const char* doc )
{
PyMethodDef m;
m.ml_name = const_cast<char*>( method_name );
@@ -81,7 +116,7 @@
}
PyMethodDef* MethodTable::table()
-{
+{
if( !mt )
{
Py_ssize_t t1size = t.size();
@@ -177,6 +212,7 @@
static PyObject* getattro_handler (PyObject*, PyObject*);
static int setattro_handler (PyObject*, PyObject*, PyObject*);
static int compare_handler (PyObject*, PyObject*);
+ static PyObject* richcompare_handler (PyObject*, PyObject*, int op);
static PyObject* repr_handler (PyObject*);
static PyObject* str_handler (PyObject*);
static long hash_handler (PyObject*);
@@ -314,7 +350,7 @@
return *this;
}
-// if you define one sequence method you must define
+// if you define one sequence method you must define
// all of them except the assigns
PythonType::PythonType( size_t basic_size, int itemsize, const char *default_name )
@@ -455,6 +491,14 @@
return *this;
}
+#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
+PythonType & PythonType::supportRichCompare()
+{
+ table->tp_richcompare = richcompare_handler;
+ return *this;
+}
+#endif
+
PythonType & PythonType::supportRepr()
{
table->tp_repr = repr_handler;
@@ -569,6 +613,21 @@
}
}
+#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
+extern "C" PyObject* richcompare_handler( PyObject *self, PyObject *other, int op )
+{
+ try
+ {
+ PythonExtensionBase *p = static_cast<PythonExtensionBase *>( self );
+ return new_reference_to( p->rich_compare( Py::Object( other ), op ) );
+ }
+ catch( Py::Exception & )
+ {
+ return NULL; // indicate error
+ }
+}
+#endif
+
extern "C" PyObject* repr_handler( PyObject *self )
{
try
@@ -1143,6 +1202,11 @@
int PythonExtensionBase::compare( const Py::Object & )
{ missing_method( compare ); return -1; }
+#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 1)
+Py::Object PythonExtensionBase::rich_compare( const Py::Object &, int op )
+{ missing_method( rich_compare ); return Py::None(); }
+#endif
+
Py::Object PythonExtensionBase::repr()
{ missing_method( repr ); return Py::Nothing(); }
@@ -1377,7 +1441,7 @@
set( PyErr_NewException( const_cast<char *>( module_name.c_str() ), parent.ptr(), NULL ), true );
}
-
+
ExtensionExceptionType::~ExtensionExceptionType()
{
}
@@ -1395,6 +1459,6 @@
Exception::Exception( PyObject* exception, Object &reason )
{
PyErr_SetObject (exception, reason.ptr());
-}
+}
} // end of namespace Py
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <js...@us...> - 2009-01-07 16:16:21
|
Revision: 6759
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6759&view=rev
Author: jswhit
Date: 2009-01-07 16:16:18 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
possible fix for gcc 4.3 (Ubuntu 8.1)
Modified Paths:
--------------
trunk/toolkits/basemap/geos-2.2.3/source/index/quadtree/DoubleBits.cpp
Modified: trunk/toolkits/basemap/geos-2.2.3/source/index/quadtree/DoubleBits.cpp
===================================================================
--- trunk/toolkits/basemap/geos-2.2.3/source/index/quadtree/DoubleBits.cpp 2009-01-07 15:56:56 UTC (rev 6758)
+++ trunk/toolkits/basemap/geos-2.2.3/source/index/quadtree/DoubleBits.cpp 2009-01-07 16:16:18 UTC (rev 6759)
@@ -15,6 +15,7 @@
#include <geos/indexQuadtree.h>
#include <geos/util.h>
+#include <string>
#include <cstring>
namespace geos {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <js...@us...> - 2009-01-07 15:57:13
|
Revision: 6758
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6758&view=rev
Author: jswhit
Date: 2009-01-07 15:56:56 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
fix typo
Modified Paths:
--------------
trunk/toolkits/basemap/doc/users/installing.rst
Modified: trunk/toolkits/basemap/doc/users/installing.rst
===================================================================
--- trunk/toolkits/basemap/doc/users/installing.rst 2009-01-07 00:07:41 UTC (rev 6757)
+++ trunk/toolkits/basemap/doc/users/installing.rst 2009-01-07 15:56:56 UTC (rev 6758)
@@ -87,7 +87,7 @@
by running ``from mpl_toolkits.basemap import Basemap`` at the python
prompt.
- Basemap includes three auxilliary packages, pydap, pyshapelib httplib2.
+ Basemap includes three auxilliary packages, pydap, pyshapelib and httplib2.
By default, setup.py checks to
see if these are already installed, and if so does not try to overwrite
them. If you get import errors related to any of these packages,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ef...@us...> - 2009-01-07 00:07:43
|
Revision: 6757
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6757&view=rev
Author: efiring
Date: 2009-01-07 00:07:41 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
Fix bug introduced in 6755 and modified in 6756--problem using svnmerge?
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 23:38:46 UTC (rev 6756)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-07 00:07:41 UTC (rev 6757)
@@ -873,8 +873,6 @@
tlinestyles = tlinestyles * nreps
if len(tlinestyles) > Nlev:
tlinestyles = tlinestyles[:Nlev]
- elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
- tlinestyles = list(linestyles)[:Nlev]
else:
raise ValueError("Unrecognized type for linestyles kwarg")
return tlinestyles
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jr...@us...> - 2009-01-06 23:38:49
|
Revision: 6756
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6756&view=rev
Author: jrevans
Date: 2009-01-06 23:38:46 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fixed a typo, an elif was placed after the else part of an 'if' statement.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 20:57:28 UTC (rev 6755)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 23:38:46 UTC (rev 6756)
@@ -873,10 +873,10 @@
tlinestyles = tlinestyles * nreps
if len(tlinestyles) > Nlev:
tlinestyles = tlinestyles[:Nlev]
+ elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
+ tlinestyles = list(linestyles)[:Nlev]
else:
raise ValueError("Unrecognized type for linestyles kwarg")
- elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
- tlinestyles = list(linestyles)[:Nlev]
return tlinestyles
def get_alpha(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 20:57:30
|
Revision: 6755
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6755&view=rev
Author: mdboom
Date: 2009-01-06 20:57:28 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Merged revisions 6752,6754 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint
........
r6752 | efiring | 2009-01-06 14:56:03 -0500 (Tue, 06 Jan 2009) | 2 lines
Backport 6745, 6746 from trunk
........
r6754 | mdboom | 2009-01-06 15:51:53 -0500 (Tue, 06 Jan 2009) | 1 line
Update git instructions with information about working on branches.
........
Modified Paths:
--------------
trunk/matplotlib/doc/devel/coding_guide.rst
trunk/matplotlib/lib/matplotlib/contour.py
Property Changed:
----------------
trunk/matplotlib/
trunk/matplotlib/doc/pyplots/README
trunk/matplotlib/doc/sphinxext/gen_gallery.py
trunk/matplotlib/doc/sphinxext/gen_rst.py
Property changes on: trunk/matplotlib
___________________________________________________________________
Modified: svnmerge-integrated
- /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6732
+ /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6754
Modified: svn:mergeinfo
- /branches/v0_91_maint:5753-5771
/branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732
+ /branches/v0_91_maint:5753-5771
/branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754
Modified: trunk/matplotlib/doc/devel/coding_guide.rst
===================================================================
--- trunk/matplotlib/doc/devel/coding_guide.rst 2009-01-06 20:51:53 UTC (rev 6754)
+++ trunk/matplotlib/doc/devel/coding_guide.rst 2009-01-06 20:57:28 UTC (rev 6755)
@@ -174,7 +174,7 @@
cd mpl.git
git config --add remote.origin.fetch +refs/remotes/*:refs/remotes/*
git fetch
- git svn init --trunk=trunk/matplotlib --tags=tags https://matplotlib.svn.sourceforge.net/svnroot/matplotlib
+ git svn init --branches=branches --trunk=trunk/matplotlib --tags=tags https://matplotlib.svn.sourceforge.net/svnroot/matplotlib
# Now just get the latest svn revisions from the SourceForge SVN repository
git svn fetch -r 6300:HEAD
@@ -224,6 +224,37 @@
git checkout whizbang-branch
git rebase master
+Working on a maintenance branch from git
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The matplotlib maintenance branches are also available through git.
+(Note that the ``git svn init`` line in the instructions above was
+updated to make this possible. If you created your git mirror without
+a ``--branches`` option, you will need to perform all of the steps
+again in a new directory).
+
+You can see which branches are available with::
+
+ git branch -a
+
+To switch your working copy to the 0.98.5 maintenance branch::
+
+ git checkout v0_98_5_maint
+
+Then you probably want to (as above) create a new local branch based
+on that branch::
+
+ git checkout -b whizbang-branch
+
+When you ``git svn dcommit`` from a maintenance branch, it will commit
+to that branch, not to the trunk.
+
+While it should theoretically be possible to perform merges from a git
+maintenance branch to a git trunk and then commit those changes back
+to the SVN trunk, I have yet to find the magic incantation to make
+that work. However, svnmerge as described `above <svn-merge>`_ can be
+used and in fact works quite well.
+
A note about git write access
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Property changes on: trunk/matplotlib/doc/pyplots/README
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732
+ /branches/v0_98_5_maint/doc/pyplots/README:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754
Property changes on: trunk/matplotlib/doc/sphinxext/gen_gallery.py
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771
/branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732
+ /branches/v0_91_maint/doc/_templates/gen_gallery.py:5753-5771
/branches/v0_98_5_maint/doc/sphinxext/gen_gallery.py:6660-6662,6672-6673,6714-6715,6717-6732,6752-6754
Property changes on: trunk/matplotlib/doc/sphinxext/gen_rst.py
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771
/branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732
+ /branches/v0_91_maint/doc/examples/gen_rst.py:5753-5771
/branches/v0_98_5_maint/doc/sphinxext/gen_rst.py:6714-6715,6717-6732,6752-6754
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 20:51:53 UTC (rev 6754)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 20:57:28 UTC (rev 6755)
@@ -875,6 +875,8 @@
tlinestyles = tlinestyles[:Nlev]
else:
raise ValueError("Unrecognized type for linestyles kwarg")
+ elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
+ tlinestyles = list(linestyles)[:Nlev]
return tlinestyles
def get_alpha(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 20:51:55
|
Revision: 6754
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6754&view=rev
Author: mdboom
Date: 2009-01-06 20:51:53 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Update git instructions with information about working on branches.
Modified Paths:
--------------
branches/v0_98_5_maint/doc/devel/coding_guide.rst
Modified: branches/v0_98_5_maint/doc/devel/coding_guide.rst
===================================================================
--- branches/v0_98_5_maint/doc/devel/coding_guide.rst 2009-01-06 20:31:33 UTC (rev 6753)
+++ branches/v0_98_5_maint/doc/devel/coding_guide.rst 2009-01-06 20:51:53 UTC (rev 6754)
@@ -171,7 +171,7 @@
cd mpl.git
git config --add remote.origin.fetch +refs/remotes/*:refs/remotes/*
git fetch
- git svn init --trunk=trunk/matplotlib --tags=tags https://matplotlib.svn.sourceforge.net/svnroot/matplotlib
+ git svn init --branches=branches --trunk=trunk/matplotlib --tags=tags https://matplotlib.svn.sourceforge.net/svnroot/matplotlib
# Now just get the latest svn revisions from the SourceForge SVN repository
git svn fetch -r 6300:HEAD
@@ -221,6 +221,37 @@
git checkout whizbang-branch
git rebase master
+Working on a maintenance branch from git
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The matplotlib maintenance branches are also available through git.
+(Note that the ``git svn init`` line in the instructions above was
+updated to make this possible. If you created your git mirror without
+a ``--branches`` option, you will need to perform all of the steps
+again in a new directory).
+
+You can see which branches are available with::
+
+ git branch -a
+
+To switch your working copy to the 0.98.5 maintenance branch::
+
+ git checkout v0_98_5_maint
+
+Then you probably want to (as above) create a new local branch based
+on that branch::
+
+ git checkout -b whizbang-branch
+
+When you ``git svn dcommit`` from a maintenance branch, it will commit
+to that branch, not to the trunk.
+
+While it should theoretically be possible to perform merges from a git
+maintenance branch to a git trunk and then commit those changes back
+to the SVN trunk, I have yet to find the magic incantation to make
+that work. However, svnmerge as described `above <svn-merge>`_ can be
+used and in fact works quite well.
+
A note about git write access
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ef...@us...> - 2009-01-06 20:31:34
|
Revision: 6753
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6753&view=rev
Author: efiring
Date: 2009-01-06 20:31:33 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Minor code cleanup in contour
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 19:56:03 UTC (rev 6752)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 20:31:33 UTC (rev 6753)
@@ -842,10 +842,14 @@
if linewidths is None:
tlinewidths = [(mpl.rcParams['lines.linewidth'],)] *Nlev
else:
- if cbook.iterable(linewidths) and len(linewidths) < Nlev:
- linewidths = list(linewidths) * int(np.ceil(Nlev/len(linewidths)))
- elif not cbook.iterable(linewidths) and type(linewidths) in [int, float]:
+ if not cbook.iterable(linewidths):
linewidths = [linewidths] * Nlev
+ else:
+ linewidths = list(linewidths)
+ if len(linewidths) < Nlev:
+ linewidths = linewidths * int(np.ceil(Nlev/len(linewidths)))
+ if len(linewidths) > Nlev:
+ linewidths = linewidths[:Nlev]
tlinewidths = [(w,) for w in linewidths]
return tlinewidths
@@ -862,10 +866,15 @@
else:
if cbook.is_string_like(linestyles):
tlinestyles = [linestyles] * Nlev
- elif cbook.iterable(linestyles) and len(linestyles) < Nlev:
- tlinestyles = list(linestyles) * int(np.ceil(Nlev/len(linestyles)))
- elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
- tlinestyles = list(linestyles)[:Nlev]
+ elif cbook.iterable(linestyles):
+ tlinestyles = list(linestyles)
+ if len(tlinestyles) < Nlev:
+ nreps = int(np.ceil(Nlev/len(linestyles)))
+ tlinestyles = tlinestyles * nreps
+ if len(tlinestyles) > Nlev:
+ tlinestyles = tlinestyles[:Nlev]
+ else:
+ raise ValueError("Unrecognized type for linestyles kwarg")
return tlinestyles
def get_alpha(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ef...@us...> - 2009-01-06 19:56:04
|
Revision: 6752
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6752&view=rev
Author: efiring
Date: 2009-01-06 19:56:03 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Backport 6745, 6746 from trunk
Modified Paths:
--------------
branches/v0_98_5_maint/CHANGELOG
branches/v0_98_5_maint/lib/matplotlib/contour.py
Modified: branches/v0_98_5_maint/CHANGELOG
===================================================================
--- branches/v0_98_5_maint/CHANGELOG 2009-01-06 19:52:42 UTC (rev 6751)
+++ branches/v0_98_5_maint/CHANGELOG 2009-01-06 19:56:03 UTC (rev 6752)
@@ -1,3 +1,7 @@
+2009-01-06 Fix bug in setting of dashed negative contours. - EF
+
+2009-01-06 Be fault tolerant when len(linestyles)>NLev in contour. - MM
+
2008-12-20 fix the dpi-dependent offset of Shadow. - JJL
2008-12-20 fix the hatch bug in the pdf backend. minor update
Modified: branches/v0_98_5_maint/lib/matplotlib/contour.py
===================================================================
--- branches/v0_98_5_maint/lib/matplotlib/contour.py 2009-01-06 19:52:42 UTC (rev 6751)
+++ branches/v0_98_5_maint/lib/matplotlib/contour.py 2009-01-06 19:56:03 UTC (rev 6752)
@@ -535,7 +535,7 @@
self.levels = kwargs.get('levels', None)
self.filled = kwargs.get('filled', False)
self.linewidths = kwargs.get('linewidths', None)
- self.linestyles = kwargs.get('linestyles', 'solid')
+ self.linestyles = kwargs.get('linestyles', None)
self.alpha = kwargs.get('alpha', 1.0)
self.origin = kwargs.get('origin', None)
@@ -613,9 +613,6 @@
linestyle = lstyle,
alpha=self.alpha)
- if level < 0.0 and self.monochrome:
- ls = mpl.rcParams['contour.negative_linestyle']
- col.set_linestyle(ls)
col.set_label('_nolegend_')
self.ax.add_collection(col, False)
self.collections.append(col)
@@ -857,11 +854,18 @@
Nlev = len(self.levels)
if linestyles is None:
tlinestyles = ['solid'] * Nlev
+ if self.monochrome:
+ neg_ls = mpl.rcParams['contour.negative_linestyle']
+ for i, lev in enumerate(self.levels):
+ if lev < 0.0:
+ tlinestyles[i] = neg_ls
else:
if cbook.is_string_like(linestyles):
tlinestyles = [linestyles] * Nlev
- elif cbook.iterable(linestyles) and len(linestyles) <= Nlev:
+ elif cbook.iterable(linestyles) and len(linestyles) < Nlev:
tlinestyles = list(linestyles) * int(np.ceil(Nlev/len(linestyles)))
+ elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
+ tlinestyles = list(linestyles)[:Nlev]
return tlinestyles
def get_alpha(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 19:52:44
|
Revision: 6751
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6751&view=rev
Author: mdboom
Date: 2009-01-06 19:52:42 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fix reST formatting in list of hatch patterns.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/patches.py
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 19:52:17 UTC (rev 6750)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 19:52:42 UTC (rev 6751)
@@ -252,7 +252,7 @@
Hatching is supported in the PostScript, PDF, SVG and Agg
backends only.
- ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
+ ACCEPTS: [ '/' | '\\\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
"""
self._hatch = hatch
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 19:52:19
|
Revision: 6750
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6750&view=rev
Author: mdboom
Date: 2009-01-06 19:52:17 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Make gen_rst.py quieter
Modified Paths:
--------------
trunk/matplotlib/doc/sphinxext/gen_rst.py
Modified: trunk/matplotlib/doc/sphinxext/gen_rst.py
===================================================================
--- trunk/matplotlib/doc/sphinxext/gen_rst.py 2009-01-06 19:36:29 UTC (rev 6749)
+++ trunk/matplotlib/doc/sphinxext/gen_rst.py 2009-01-06 19:52:17 UTC (rev 6750)
@@ -96,7 +96,8 @@
"""%(subdir, subdir))
- print subdir
+ sys.stdout.write(subdir + ", ")
+ sys.stdout.flush()
data = datad[subdir]
data.sort()
@@ -116,8 +117,6 @@
not out_of_date(fullpath, outrstfile)):
continue
- print ' %s'%fname
-
fh = file(outrstfile, 'w')
fh.write('.. _%s-%s:\n\n'%(subdir, basename))
title = '%s example code: %s'%(subdir, fname)
@@ -151,5 +150,7 @@
fhindex.close()
+ print
+
def setup(app):
app.connect('builder-inited', generate_example_rst)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 19:36:31
|
Revision: 6749
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6749&view=rev
Author: mdboom
Date: 2009-01-06 19:36:29 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fix stix_font_demo.py
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/mathtext.py
Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2009-01-06 19:34:52 UTC (rev 6748)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2009-01-06 19:36:29 UTC (rev 6749)
@@ -2296,7 +2296,7 @@
def _get_font(self):
return self._font
def _set_font(self, name):
- if name in Parser._fontnames:
+ if name in ('rm', 'it', 'bf'):
self.font_class = name
self._font = name
font = property(_get_font, _set_font)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 19:34:53
|
Revision: 6748
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6748&view=rev
Author: mdboom
Date: 2009-01-06 19:34:52 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fix reST formatting.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/patches.py
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 19:26:31 UTC (rev 6747)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 19:34:52 UTC (rev 6748)
@@ -249,12 +249,10 @@
hatchings are done. If same letter repeats, it increases the
density of hatching of that pattern.
- CURRENT LIMITATIONS:
+ Hatching is supported in the PostScript, PDF, SVG and Agg
+ backends only.
- 1. Hatching is supported in the PostScript, PDF, SVG and Agg
- backends only.
-
- ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | ' *' ]
+ ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
"""
self._hatch = hatch
@@ -1444,8 +1442,8 @@
else:
argstr = ",".join([("%s=%s" % (an, av)) for an, av in args])
- #adding quotes for now to work around tex bug treating '-' as itemize
- _table.append([cls.__name__, "'%s'"%name, argstr])
+ #adding ``quotes`` since - and | have special meaning in reST
+ _table.append([cls.__name__, "``%s``"%name, argstr])
return _pprint_table(_table)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 19:26:33
|
Revision: 6747
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6747&view=rev
Author: mdboom
Date: 2009-01-06 19:26:31 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Remove examples as a stage in make.py, since it is now integrated into the build as an event-triggered plugin.
Modified Paths:
--------------
trunk/matplotlib/doc/make.py
Modified: trunk/matplotlib/doc/make.py
===================================================================
--- trunk/matplotlib/doc/make.py 2009-01-06 19:22:09 UTC (rev 6746)
+++ trunk/matplotlib/doc/make.py 2009-01-06 19:26:31 UTC (rev 6747)
@@ -26,12 +26,6 @@
def figs():
os.system('cd users/figures/ && python make.py')
-def examples():
- 'make the rest examples'
-
- os.system('cd examples; svn-clean; python gen_rst.py')
- #pass
-
def html():
check_build()
shutil.copy('../lib/matplotlib/mpl-data/matplotlibrc', '_static/matplotlibrc')
@@ -75,7 +69,6 @@
def all():
#figs()
- examples()
html()
latex()
@@ -87,7 +80,6 @@
'clean' : clean,
'sf' : sf,
'sfpdf' : sfpdf,
- 'examples' : examples,
'all' : all,
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ef...@us...> - 2009-01-06 19:22:10
|
Revision: 6746
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6746&view=rev
Author: efiring
Date: 2009-01-06 19:22:09 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fix bug in setting of negative contour linestyles.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-01-06 18:59:31 UTC (rev 6745)
+++ trunk/matplotlib/CHANGELOG 2009-01-06 19:22:09 UTC (rev 6746)
@@ -1,6 +1,8 @@
+2009-01-06 Fix bug in setting of dashed negative contours. - EF
+
2009-01-06 Be fault tolerant when len(linestyles)>NLev in contour. - MM
-2009-01-06 Added marginals kwarg to hexbin to plot marginal densities
+2009-01-06 Added marginals kwarg to hexbin to plot marginal densities
JDH
2009-01-06 Change user-visible multipage pdf object to PdfPages to
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 18:59:31 UTC (rev 6745)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 19:22:09 UTC (rev 6746)
@@ -535,7 +535,7 @@
self.levels = kwargs.get('levels', None)
self.filled = kwargs.get('filled', False)
self.linewidths = kwargs.get('linewidths', None)
- self.linestyles = kwargs.get('linestyles', 'solid')
+ self.linestyles = kwargs.get('linestyles', None)
self.alpha = kwargs.get('alpha', 1.0)
self.origin = kwargs.get('origin', None)
@@ -613,9 +613,6 @@
linestyle = lstyle,
alpha=self.alpha)
- if level < 0.0 and self.monochrome:
- ls = mpl.rcParams['contour.negative_linestyle']
- col.set_linestyle(ls)
col.set_label('_nolegend_')
self.ax.add_collection(col, False)
self.collections.append(col)
@@ -857,6 +854,11 @@
Nlev = len(self.levels)
if linestyles is None:
tlinestyles = ['solid'] * Nlev
+ if self.monochrome:
+ neg_ls = mpl.rcParams['contour.negative_linestyle']
+ for i, lev in enumerate(self.levels):
+ if lev < 0.0:
+ tlinestyles[i] = neg_ls
else:
if cbook.is_string_like(linestyles):
tlinestyles = [linestyles] * Nlev
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mme...@us...> - 2009-01-06 18:59:34
|
Revision: 6745
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6745&view=rev
Author: mmetz_bn
Date: 2009-01-06 18:59:31 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Fault tolerant handling of linestyles when too many
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/contour.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-01-06 17:24:32 UTC (rev 6744)
+++ trunk/matplotlib/CHANGELOG 2009-01-06 18:59:31 UTC (rev 6745)
@@ -1,3 +1,5 @@
+2009-01-06 Be fault tolerant when len(linestyles)>NLev in contour. - MM
+
2009-01-06 Added marginals kwarg to hexbin to plot marginal densities
JDH
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 17:24:32 UTC (rev 6744)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2009-01-06 18:59:31 UTC (rev 6745)
@@ -860,8 +860,10 @@
else:
if cbook.is_string_like(linestyles):
tlinestyles = [linestyles] * Nlev
- elif cbook.iterable(linestyles) and len(linestyles) <= Nlev:
+ elif cbook.iterable(linestyles) and len(linestyles) < Nlev:
tlinestyles = list(linestyles) * int(np.ceil(Nlev/len(linestyles)))
+ elif cbook.iterable(linestyles): # len(linestyles) >= Nlev
+ tlinestyles = list(linestyles)[:Nlev]
return tlinestyles
def get_alpha(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <md...@us...> - 2009-01-06 17:24:35
|
Revision: 6744
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6744&view=rev
Author: mdboom
Date: 2009-01-06 17:24:32 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Add more hatch styles. Improve consistency across backends.
Modified Paths:
--------------
trunk/matplotlib/examples/pylab_examples/hatch_demo.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
trunk/matplotlib/lib/matplotlib/patches.py
trunk/matplotlib/lib/matplotlib/path.py
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_backend_agg.h
Added Paths:
-----------
trunk/matplotlib/lib/matplotlib/hatch.py
Modified: trunk/matplotlib/examples/pylab_examples/hatch_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/hatch_demo.py 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/examples/pylab_examples/hatch_demo.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -6,17 +6,18 @@
fig = plt.figure()
ax1 = fig.add_subplot(121)
-ax1.annotate("Hatch is only supported in the PS and PDF backend", (1, 1),
+ax1.annotate("Hatch is only supported in the PS, PDF, SVG and Agg backends", (1, 1),
xytext=(0, 5),
xycoords="axes fraction", textcoords="offset points", ha="center"
)
-ax1.bar(range(1,5), range(1,5), color='gray', edgecolor='black', hatch="/")
+ax1.bar(range(1,5), range(1,5), color='red', edgecolor='black', hatch="/")
+ax1.bar(range(1,5), [6] * 4, bottom=range(1,5), color='blue', edgecolor='black', hatch='//')
-
ax2 = fig.add_subplot(122)
-bars = ax2.bar(range(1,5), range(1,5), color='gray', ecolor='black')
+bars = ax2.bar(range(1,5), range(1,5), color='yellow', ecolor='black') + \
+ ax2.bar(range(1, 5), [6] * 4, bottom=range(1,5), color='green', ecolor='black')
-patterns = ('/', '+', 'x', '\\')
+patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.')
for bar, pattern in zip(bars, patterns):
bar.set_hatch(pattern)
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -557,7 +557,7 @@
'FirstChar': 0,
'LastChar': len(fontinfo.dvifont.widths) - 1,
'Widths': widthsObject,
- }
+ }
# Encoding (if needed)
if fontinfo.encodingfile is not None:
@@ -595,7 +595,7 @@
fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
self.type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
fontdict['FontDescriptor'] = fontdesc
-
+
self.writeObject(fontdictObject, fontdict)
return fontdictObject
@@ -1749,7 +1749,6 @@
else:
return [Name('DeviceRGB'), Op.setcolorspace_nonstroke]
else:
- hatch = hatch.lower()
hatch_style = (self._rgb, self._fillcolor, hatch)
name = self.file.hatchPattern(hatch_style)
return [Name('Pattern'), Op.setcolorspace_nonstroke,
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_svg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_svg.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -95,17 +95,22 @@
"""
Create a new hatch pattern
"""
- HATCH_SIZE = 144
- dictkey = (gc.get_hatch().lower(), rgbFace, gc.get_rgb())
+ HATCH_SIZE = 72
+ dictkey = (gc.get_hatch(), rgbFace, gc.get_rgb())
id = self._hatchd.get(dictkey)
if id is None:
id = 'h%s' % md5(str(dictkey)).hexdigest()
self._svgwriter.write('<defs>\n <pattern id="%s" ' % id)
self._svgwriter.write('patternUnits="userSpaceOnUse" x="0" y="0" ')
self._svgwriter.write(' width="%d" height="%d" >\n' % (HATCH_SIZE, HATCH_SIZE))
- path_data = self._convert_path(gc.get_hatch_path(), Affine2D().scale(144))
+ path_data = self._convert_path(
+ gc.get_hatch_path(),
+ Affine2D().scale(HATCH_SIZE).scale(1.0, -1.0).translate(0, HATCH_SIZE))
+ self._svgwriter.write(
+ '<rect x="0" y="0" width="%d" height="%d" fill="%s"/>' %
+ (HATCH_SIZE+1, HATCH_SIZE+1, rgb2hex(rgbFace)))
path = '<path d="%s" fill="%s" stroke="%s" stroke-width="1.0"/>' % (
- path_data, rgb2hex(rgbFace[:3]), rgb2hex(gc.get_rgb()[:3]))
+ path_data, rgb2hex(gc.get_rgb()[:3]), rgb2hex(gc.get_rgb()[:3]))
self._svgwriter.write(path)
self._svgwriter.write('\n </pattern>\n</defs>')
self._hatchd[dictkey] = id
Added: trunk/matplotlib/lib/matplotlib/hatch.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/hatch.py (rev 0)
+++ trunk/matplotlib/lib/matplotlib/hatch.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -0,0 +1,194 @@
+"""
+Contains a classes for generating hatch patterns.
+"""
+
+import numpy as np
+from matplotlib.path import Path
+
+class HatchPatternBase:
+ """
+ The base class for a hatch pattern.
+ """
+ pass
+
+class HorizontalHatch(HatchPatternBase):
+ def __init__(self, hatch, density):
+ self.num_lines = (hatch.count('-') + hatch.count('+')) * density
+ self.num_vertices = self.num_lines * 2
+
+ def set_vertices_and_codes(self, vertices, codes):
+ steps = np.linspace(0.0, 1.0, self.num_lines, False)
+ vertices[0::2, 0] = 0.0
+ vertices[0::2, 1] = steps
+ vertices[1::2, 0] = 1.0
+ vertices[1::2, 1] = steps
+ codes[0::2] = Path.MOVETO
+ codes[1::2] = Path.LINETO
+
+class VerticalHatch(HatchPatternBase):
+ def __init__(self, hatch, density):
+ self.num_lines = (hatch.count('|') + hatch.count('+')) * density
+ self.num_vertices = self.num_lines * 2
+
+ def set_vertices_and_codes(self, vertices, codes):
+ steps = np.linspace(0.0, 1.0, self.num_lines, False)
+ vertices[0::2, 0] = steps
+ vertices[0::2, 1] = 0.0
+ vertices[1::2, 0] = steps
+ vertices[1::2, 1] = 1.0
+ codes[0::2] = Path.MOVETO
+ codes[1::2] = Path.LINETO
+
+class NorthEastHatch(HatchPatternBase):
+ def __init__(self, hatch, density):
+ self.num_lines = (hatch.count('/') + hatch.count('x') + hatch.count('X')) * density
+ self.num_vertices = self.num_lines * 4
+
+ def set_vertices_and_codes(self, vertices, codes):
+ steps = np.linspace(0.0, 1.0, self.num_lines, False)
+ rev_steps = 1.0 - steps
+ vertices[0::4, 0] = 0.0
+ vertices[0::4, 1] = steps
+ vertices[1::4, 0] = rev_steps
+ vertices[1::4, 1] = 1.0
+ vertices[2::4, 0] = rev_steps
+ vertices[2::4, 1] = 0.0
+ vertices[3::4, 0] = 1.0
+ vertices[3::4, 1] = steps
+ codes[0::2] = Path.MOVETO
+ codes[1::2] = Path.LINETO
+
+class SouthEastHatch(HatchPatternBase):
+ def __init__(self, hatch, density):
+ self.num_lines = (hatch.count('\\') + hatch.count('x') + hatch.count('X')) * density
+ self.num_vertices = self.num_lines * 4
+
+ def set_vertices_and_codes(self, vertices, codes):
+ steps = np.linspace(0.0, 1.0, self.num_lines, False)
+ vertices[0::4, 0] = 1.0
+ vertices[0::4, 1] = steps
+ vertices[1::4, 0] = steps
+ vertices[1::4, 1] = 1.0
+ vertices[2::4, 0] = steps
+ vertices[2::4, 1] = 0.0
+ vertices[3::4, 0] = 0.0
+ vertices[3::4, 1] = steps
+ codes[0::2] = Path.MOVETO
+ codes[1::2] = Path.LINETO
+
+class Shapes(HatchPatternBase):
+ filled = False
+ def __init__(self, hatch, density):
+ if self.num_rows == 0:
+ self.num_shapes = 0
+ self.num_vertices = 0
+ else:
+ self.num_shapes = ((self.num_rows / 2 + 1) * (self.num_rows + 1) +
+ (self.num_rows / 2) * (self.num_rows))
+ self.num_vertices = (self.num_shapes *
+ len(self.shape_vertices) *
+ (self.filled and 1 or 2))
+
+ def set_vertices_and_codes(self, vertices, codes):
+ offset = 1.0 / self.num_rows
+ shape_vertices = self.shape_vertices * offset * self.size
+ if not self.filled:
+ inner_vertices = shape_vertices[::-1] * 0.9
+ shape_codes = self.shape_codes
+ shape_size = len(shape_vertices)
+
+ cursor = 0
+ for row in xrange(self.num_rows + 1):
+ if row % 2 == 0:
+ cols = np.linspace(0.0, 1.0, self.num_rows + 1, True)
+ else:
+ cols = np.linspace(offset / 2.0, 1.0 - offset / 2.0, self.num_rows, True)
+ row_pos = row * offset
+ for col_pos in cols:
+ vertices[cursor:cursor+shape_size] = shape_vertices + (col_pos, row_pos)
+ codes[cursor:cursor+shape_size] = shape_codes
+ cursor += shape_size
+ if not self.filled:
+ vertices[cursor:cursor+shape_size] = inner_vertices + (col_pos, row_pos)
+ codes[cursor:cursor+shape_size] = shape_codes
+ cursor += shape_size
+
+class Circles(Shapes):
+ def __init__(self, hatch, density):
+ path = Path.unit_circle()
+ self.shape_vertices = path.vertices
+ self.shape_codes = path.codes
+ Shapes.__init__(self, hatch, density)
+
+class SmallCircles(Circles):
+ size = 0.2
+
+ def __init__(self, hatch, density):
+ self.num_rows = (hatch.count('o')) * density
+ Circles.__init__(self, hatch, density)
+
+class LargeCircles(Circles):
+ size = 0.35
+
+ def __init__(self, hatch, density):
+ self.num_rows = (hatch.count('O')) * density
+ Circles.__init__(self, hatch, density)
+
+class SmallFilledCircles(SmallCircles):
+ size = 0.1
+ filled = True
+
+ def __init__(self, hatch, density):
+ self.num_rows = (hatch.count('.')) * density
+ Circles.__init__(self, hatch, density)
+
+class Stars(Shapes):
+ size = 1.0 / 3.0
+ filled = True
+
+ def __init__(self, hatch, density):
+ self.num_rows = (hatch.count('*')) * density
+ path = Path.unit_regular_star(5)
+ self.shape_vertices = path.vertices
+ self.shape_codes = np.ones(len(self.shape_vertices)) * Path.LINETO
+ self.shape_codes[0] = Path.MOVETO
+ Shapes.__init__(self, hatch, density)
+
+_hatch_types = [
+ HorizontalHatch,
+ VerticalHatch,
+ NorthEastHatch,
+ SouthEastHatch,
+ SmallCircles,
+ LargeCircles,
+ SmallFilledCircles,
+ Stars
+ ]
+
+def get_path(hatchpattern, density=6):
+ """
+ Given a hatch specifier, *hatchpattern*, generates Path to render
+ the hatch in a unit square. *density* is the number of lines per
+ unit square.
+ """
+ size = 1.0
+ density = int(density)
+
+ patterns = [hatch_type(hatchpattern, density) for hatch_type in _hatch_types]
+ num_vertices = sum([pattern.num_vertices for pattern in patterns])
+
+ if num_vertices == 0:
+ return Path(np.empty((0, 2)))
+
+ vertices = np.empty((num_vertices, 2))
+ codes = np.empty((num_vertices,), np.uint8)
+
+ cursor = 0
+ for pattern in patterns:
+ if pattern.num_vertices != 0:
+ vertices_chunk = vertices[cursor:cursor + pattern.num_vertices]
+ codes_chunk = codes[cursor:cursor + pattern.num_vertices]
+ pattern.set_vertices_and_codes(vertices_chunk, codes_chunk)
+ cursor += pattern.num_vertices
+
+ return Path(vertices, codes)
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -238,19 +238,23 @@
\ - back diagonal
| - vertical
- - horizontal
- # - crossed
+ + - crossed
x - crossed diagonal
+ o - small circle
+ O - large circle
+ . - dots
+ * - stars
Letters can be combined, in which case all the specified
hatchings are done. If same letter repeats, it increases the
- density of hatching in that direction.
+ density of hatching of that pattern.
CURRENT LIMITATIONS:
1. Hatching is supported in the PostScript, PDF, SVG and Agg
backends only.
- ACCEPTS: [ '/' | '\\' | '|' | '-' | '#' | 'x' ] (ps & pdf backend only)
+ ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | ' *' ]
"""
self._hatch = hatch
Modified: trunk/matplotlib/lib/matplotlib/path.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/path.py 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/lib/matplotlib/path.py 2009-01-06 17:24:32 UTC (rev 6744)
@@ -572,87 +572,17 @@
can be used in a repeated hatching pattern. *density* is the
number of lines per unit square.
"""
+ from matplotlib.hatch import get_path
+
if hatchpattern is None:
return None
- hatch = hatchpattern.lower()
- hatch_path = cls._hatch_dict.get((hatch, density))
+ hatch_path = cls._hatch_dict.get((hatchpattern, density))
if hatch_path is not None:
return hatch_path
- size = 1.0
- density = int(density)
- counts = [
- hatch.count('-') + hatch.count('+'),
- hatch.count('/') + hatch.count('x'),
- hatch.count('|') + hatch.count('+'),
- hatch.count('\\') + hatch.count('x')
- ]
-
- if sum(counts) == 0:
- return cls([])
-
- counts = [x * density for x in counts]
-
- num_vertices = (counts[0] * 2 + counts[1] * 4 +
- counts[2] * 2 + counts[3] * 4)
- vertices = np.empty((num_vertices, 2))
- codes = np.empty((num_vertices,), cls.code_type)
- codes[0::2] = cls.MOVETO
- codes[1::2] = cls.LINETO
-
- cursor = 0
-
- # - horizontal
- if counts[0]:
- vertices_chunk = vertices[cursor:cursor + counts[0] * 2]
- cursor += counts[0] * 2
- steps = np.linspace(0.0, 1.0, counts[0], False)
- vertices_chunk[0::2, 0] = 0.0
- vertices_chunk[0::2, 1] = steps
- vertices_chunk[1::2, 0] = size
- vertices_chunk[1::2, 1] = steps
-
- # / ne
- if counts[1]:
- vertices_chunk = vertices[cursor:cursor + counts[1] * 4]
- cursor += counts[1] * 4
- steps = np.linspace(0.0, 1.0, counts[1], False)
- vertices_chunk[0::4, 0] = 0.0
- vertices_chunk[0::4, 1] = steps
- vertices_chunk[1::4, 0] = size - steps
- vertices_chunk[1::4, 1] = size
- vertices_chunk[2::4, 0] = size - steps
- vertices_chunk[2::4, 1] = 0.0
- vertices_chunk[3::4, 0] = size
- vertices_chunk[3::4, 1] = steps
-
- # | vertical
- if counts[2]:
- vertices_chunk = vertices[cursor:cursor + counts[2] * 2]
- cursor += counts[2] * 2
- steps = np.linspace(0.0, 1.0, counts[2], False)
- vertices_chunk[0::2, 0] = steps
- vertices_chunk[0::2, 1] = 0.0
- vertices_chunk[1::2, 0] = steps
- vertices_chunk[1::2, 1] = size
-
- # \ se
- if counts[3]:
- vertices_chunk = vertices[cursor:cursor + counts[3] * 4]
- cursor += counts[3] * 4
- steps = np.linspace(0.0, 1.0, counts[3], False)
- vertices_chunk[0::4, 0] = size
- vertices_chunk[0::4, 1] = steps
- vertices_chunk[1::4, 0] = steps
- vertices_chunk[1::4, 1] = size
- vertices_chunk[2::4, 0] = steps
- vertices_chunk[2::4, 1] = 0.0
- vertices_chunk[3::4, 0] = 0.0
- vertices_chunk[3::4, 1] = steps
-
- hatch_path = cls(vertices, codes)
- cls._hatch_dict[(hatch, density)] = hatch_path
+ hatch_path = get_path(hatchpattern, density)
+ cls._hatch_dict[(hatchpattern, density)] = hatch_path
return hatch_path
hatch = classmethod(hatch)
Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/src/_backend_agg.cpp 2009-01-06 17:24:32 UTC (rev 6744)
@@ -901,18 +901,20 @@
// Create and transform the path
typedef agg::conv_transform<PathIterator> hatch_path_trans_t;
typedef SimplifyPath<hatch_path_trans_t> hatch_path_simplify_t;
- typedef agg::conv_stroke<hatch_path_simplify_t> hatch_path_stroke_t;
+ typedef agg::conv_curve<hatch_path_simplify_t> hatch_path_curve_t;
+ typedef agg::conv_stroke<hatch_path_curve_t> hatch_path_stroke_t;
PathIterator hatch_path(gc.hatchpath);
agg::trans_affine hatch_trans;
+ hatch_trans *= agg::trans_affine_scaling(1.0, -1.0);
+ hatch_trans *= agg::trans_affine_translation(0.0, 1.0);
hatch_trans *= agg::trans_affine_scaling(HATCH_SIZE, HATCH_SIZE);
hatch_path_trans_t hatch_path_trans(hatch_path, hatch_trans);
- hatch_path_simplify_t hatch_path_simplify
- (hatch_path_trans, true, false, HATCH_SIZE, HATCH_SIZE);
- hatch_path_stroke_t hatch_path_stroke(hatch_path_simplify);
+ hatch_path_simplify_t hatch_path_simplify(hatch_path_trans, false, false, HATCH_SIZE, HATCH_SIZE);
+ hatch_path_curve_t hatch_path_curve(hatch_path_simplify);
+ hatch_path_stroke_t hatch_path_stroke(hatch_path_curve);
hatch_path_stroke.width(1.0);
hatch_path_stroke.line_cap(agg::square_cap);
- theRasterizer.add_path(hatch_path_stroke);
// Render the path into the hatch buffer
pixfmt hatch_img_pixf(hatchRenderingBuffer);
@@ -920,7 +922,11 @@
renderer_aa rs(rb);
rb.clear(agg::rgba(0.0, 0.0, 0.0, 0.0));
rs.color(gc.color);
+
+ theRasterizer.add_path(hatch_path_curve);
agg::render_scanlines(theRasterizer, slineP8, rs);
+ theRasterizer.add_path(hatch_path_stroke);
+ agg::render_scanlines(theRasterizer, slineP8, rs);
// Put clipping back on, if originally set on entry to this
// function
Modified: trunk/matplotlib/src/_backend_agg.h
===================================================================
--- trunk/matplotlib/src/_backend_agg.h 2009-01-06 17:06:06 UTC (rev 6743)
+++ trunk/matplotlib/src/_backend_agg.h 2009-01-06 17:24:32 UTC (rev 6744)
@@ -208,9 +208,7 @@
Py::Object lastclippath;
agg::trans_affine lastclippath_transform;
- // HATCH_SIZE should be a power of 2, to take advantage of Agg's
- // fast pattern rendering
- static const size_t HATCH_SIZE = 128;
+ static const size_t HATCH_SIZE = 72;
agg::int8u hatchBuffer[HATCH_SIZE * HATCH_SIZE * 4];
agg::rendering_buffer hatchRenderingBuffer;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jd...@us...> - 2009-01-06 17:06:08
|
Revision: 6743
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6743&view=rev
Author: jdh2358
Date: 2009-01-06 17:06:06 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
added marginal density option to hexbin
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/boilerplate.py
trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/setupext.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-01-06 16:53:09 UTC (rev 6742)
+++ trunk/matplotlib/CHANGELOG 2009-01-06 17:06:06 UTC (rev 6743)
@@ -1,3 +1,6 @@
+2009-01-06 Added marginals kwarg to hexbin to plot marginal densities
+ JDH
+
2009-01-06 Change user-visible multipage pdf object to PdfPages to
avoid accidents with the file-like PdfFile. - JKS
Modified: trunk/matplotlib/boilerplate.py
===================================================================
--- trunk/matplotlib/boilerplate.py 2009-01-06 16:53:09 UTC (rev 6742)
+++ trunk/matplotlib/boilerplate.py 2009-01-06 17:06:06 UTC (rev 6743)
@@ -102,7 +102,7 @@
cmappable = {
'contour' : 'if ret._A is not None: gci._current = ret',
'contourf': 'if ret._A is not None: gci._current = ret',
- 'hexbin' : 'gci._current = ret',
+ 'hexbin' : 'gci._current = ret[0]',
'scatter' : 'gci._current = ret',
'pcolor' : 'gci._current = ret',
'pcolormesh' : 'gci._current = ret',
Modified: trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py 2009-01-06 16:53:09 UTC (rev 6742)
+++ trunk/matplotlib/examples/pylab_examples/hexbin_demo2.py 2009-01-06 17:06:06 UTC (rev 6743)
@@ -39,13 +39,14 @@
gridsize=30
plt.subplot(211)
-plt.hexbin(x,y, C=z, gridsize=gridsize )
+plt.hexbin(x,y, C=z, gridsize=gridsize, marginals=True)
plt.axis([xmin, xmax, ymin, ymax])
cb = plt.colorbar()
cb.set_label('mean value')
+
plt.subplot(212)
-plt.hexbin(x,y, gridsize=gridsize )
+plt.hexbin(x,y, gridsize=gridsize)
plt.axis([xmin, xmax, ymin, ymax])
cb = plt.colorbar()
cb.set_label('N observations')
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2009-01-06 16:53:09 UTC (rev 6742)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2009-01-06 17:06:06 UTC (rev 6743)
@@ -5212,7 +5212,7 @@
xscale = 'linear', yscale = 'linear',
cmap=None, norm=None, vmin=None, vmax=None,
alpha=1.0, linewidths=None, edgecolors='none',
- reduce_C_function = np.mean, mincnt=None,
+ reduce_C_function = np.mean, mincnt=None, marginals=True,
**kwargs):
"""
call signature::
@@ -5221,7 +5221,7 @@
xscale = 'linear', yscale = 'linear',
cmap=None, norm=None, vmin=None, vmax=None,
alpha=1.0, linewidths=None, edgecolors='none'
- reduce_C_function = np.mean, mincnt=None,
+ reduce_C_function = np.mean, mincnt=None, marginals=True
**kwargs)
Make a hexagonal binning plot of *x* versus *y*, where *x*,
@@ -5273,6 +5273,11 @@
If not None, only display cells with more than *mincnt*
number of points in the cell
+ *marginals*: True|False
+ if marginals is True, plot the marginal density as
+ colormapped rectagles along the bottom of the x-axis and
+ left of the y-axis
+
Other keyword arguments controlling color mapping and normalization
arguments:
@@ -5320,8 +5325,11 @@
:class:`~matplotlib.collections.PolyCollection` instance; use
:meth:`~matplotlib.collection.PolyCollection.get_array` on
this :class:`~matplotlib.collections.PolyCollection` to get
- the counts in each hexagon.
+ the counts in each hexagon.. If marginals is True, horizontal
+ bar and vertical bar (both PolyCollections) will be attached
+ to the return collection as attributes *hbar* and *vbar*
+
**Example:**
.. plot:: mpl_examples/pylab_examples/hexbin_demo.py
@@ -5331,8 +5339,10 @@
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
+
x, y, C = cbook.delete_masked_points(x, y, C)
+
# Set the size of the hexagon grid
if iterable(gridsize):
nx, ny = gridsize
@@ -5357,6 +5367,11 @@
xmax += padding
sx = (xmax-xmin) / nx
sy = (ymax-ymin) / ny
+
+ if marginals:
+ xorig = x.copy()
+ yorig = y.copy()
+
x = (x-xmin)/sx
y = (y-ymin)/sy
ix1 = np.round(x).astype(int)
@@ -5496,6 +5511,93 @@
# add the collection last
self.add_collection(collection)
+ if not marginals:
+ return collection
+
+
+ if C is None:
+ C = np.ones(len(x))
+
+ def coarse_bin(x, y, coarse):
+ ind = coarse.searchsorted(x).clip(0, len(coarse)-1)
+ mus = np.zeros(len(coarse))
+ for i in range(len(coarse)):
+ mu = reduce_C_function(y[ind==i])
+ mus[i] = mu
+ return mus
+
+ coarse = np.linspace(xmin, xmax, gridsize)
+
+ xcoarse = coarse_bin(xorig, C, coarse)
+ valid = ~np.isnan(xcoarse)
+ verts, values = [], []
+ for i,val in enumerate(xcoarse):
+ thismin = coarse[i]
+ if i<len(coarse)-1:
+ thismax = coarse[i+1]
+ else:
+ thismax = thismin + np.diff(coarse)[-1]
+
+ if not valid[i]: continue
+
+ verts.append([(thismin, 0), (thismin, 0.05), (thismax, 0.05), (thismax, 0)])
+ values.append(val)
+
+ values = np.array(values)
+ trans = mtransforms.blended_transform_factory(
+ self.transData, self.transAxes)
+
+
+ hbar = mcoll.PolyCollection(verts, transform=trans, edgecolors='face')
+
+ hbar.set_array(values)
+ hbar.set_cmap(cmap)
+ hbar.set_norm(norm)
+ hbar.set_alpha(alpha)
+ hbar.update(kwargs)
+ self.add_collection(hbar)
+
+ coarse = np.linspace(ymin, ymax, gridsize)
+ ycoarse = coarse_bin(yorig, C, coarse)
+ valid = ~np.isnan(ycoarse)
+ verts, values = [], []
+ for i,val in enumerate(ycoarse):
+ thismin = coarse[i]
+ if i<len(coarse)-1:
+ thismax = coarse[i+1]
+ else:
+ thismax = thismin + np.diff(coarse)[-1]
+ if not valid[i]: continue
+ verts.append([(0, thismin), (0.0, thismax), (0.05, thismax), (0.05, thismin)])
+ values.append(val)
+
+ values = np.array(values)
+
+
+ trans = mtransforms.blended_transform_factory(
+ self.transAxes, self.transData)
+
+ vbar = mcoll.PolyCollection(verts, transform=trans, edgecolors='face')
+ vbar.set_array(values)
+ vbar.set_cmap(cmap)
+ vbar.set_norm(norm)
+ vbar.set_alpha(alpha)
+ vbar.update(kwargs)
+ self.add_collection(vbar)
+
+
+
+ collection.hbar = hbar
+ collection.vbar = vbar
+
+ def on_changed(collection):
+ hbar.set_cmap(collection.get_cmap())
+ hbar.set_clim(collection.get_clim())
+ vbar.set_cmap(collection.get_cmap())
+ vbar.set_clim(collection.get_clim())
+
+ collection.callbacksSM.connect('changed', on_changed)
+
return collection
hexbin.__doc__ = cbook.dedent(hexbin.__doc__) % martist.kwdocd
Modified: trunk/matplotlib/setupext.py
===================================================================
--- trunk/matplotlib/setupext.py 2009-01-06 16:53:09 UTC (rev 6742)
+++ trunk/matplotlib/setupext.py 2009-01-06 17:06:06 UTC (rev 6743)
@@ -1066,8 +1066,7 @@
global BUILT_WINDOWING
if BUILT_WINDOWING: return # only build it if you you haven't already
module = Extension('matplotlib._windowing',
- ['src/_windowing.cpp',
- ],
+ ['src/_windowing.cpp'],
)
add_windowing_flags(module)
ext_modules.append(module)
@@ -1341,7 +1340,7 @@
temp_copy('src/_backend_gdk.c', 'src/backend_gdk.c')
module = Extension(
'matplotlib.backends._backend_gdk',
- ['src/backend_gdk.c', ],
+ ['src/backend_gdk.c'],
libraries = [],
include_dirs=numpy_inc_dirs,
)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <js...@us...> - 2009-01-06 16:53:12
|
Revision: 6742
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6742&view=rev
Author: jswhit
Date: 2009-01-06 16:53:09 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
update release number
Modified Paths:
--------------
trunk/toolkits/basemap/doc/conf.py
Modified: trunk/toolkits/basemap/doc/conf.py
===================================================================
--- trunk/toolkits/basemap/doc/conf.py 2009-01-06 16:40:30 UTC (rev 6741)
+++ trunk/toolkits/basemap/doc/conf.py 2009-01-06 16:53:09 UTC (rev 6742)
@@ -48,7 +48,7 @@
# The short X.Y version.
version = '0.99.3'
# The full version, including alpha/beta/rc tags.
-release = '0.99.2'
+release = '0.99.3'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <js...@us...> - 2009-01-06 16:40:31
|
Revision: 6741
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6741&view=rev
Author: jswhit
Date: 2009-01-06 16:40:30 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
update version number
Modified Paths:
--------------
trunk/toolkits/basemap/doc/conf.py
Modified: trunk/toolkits/basemap/doc/conf.py
===================================================================
--- trunk/toolkits/basemap/doc/conf.py 2009-01-06 16:38:47 UTC (rev 6740)
+++ trunk/toolkits/basemap/doc/conf.py 2009-01-06 16:40:30 UTC (rev 6741)
@@ -46,7 +46,7 @@
# other places throughout the built documents.
#
# The short X.Y version.
-version = '0.99.2'
+version = '0.99.3'
# The full version, including alpha/beta/rc tags.
release = '0.99.2'
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <js...@us...> - 2009-01-06 16:38:50
|
Revision: 6740
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6740&view=rev
Author: jswhit
Date: 2009-01-06 16:38:47 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
add fulldisk aeqd example.
Modified Paths:
--------------
trunk/toolkits/basemap/doc/users/aeqd.rst
Added Paths:
-----------
trunk/toolkits/basemap/doc/users/figures/aeqd_fulldisk.py
Modified: trunk/toolkits/basemap/doc/users/aeqd.rst
===================================================================
--- trunk/toolkits/basemap/doc/users/aeqd.rst 2009-01-06 08:07:18 UTC (rev 6739)
+++ trunk/toolkits/basemap/doc/users/aeqd.rst 2009-01-06 16:38:47 UTC (rev 6740)
@@ -10,6 +10,15 @@
this point are equidistant on the surface of the earth on this projection.
The specified point ``lon_0, lat_0`` shows up as a black dot in the center of the map.
+Here's an example using the width and height keywords to specify the map region.
+
.. literalinclude:: figures/aeqd.py
.. image:: figures/aeqd.png
+
+If both the width/height and corner lat/lon keywords are omitted, the whole world is
+plotted in a circle.
+
+.. literalinclude:: figures/aeqd_fulldisk.py
+
+.. image:: figures/aeqd_fulldisk.png
Added: trunk/toolkits/basemap/doc/users/figures/aeqd_fulldisk.py
===================================================================
--- trunk/toolkits/basemap/doc/users/figures/aeqd_fulldisk.py (rev 0)
+++ trunk/toolkits/basemap/doc/users/figures/aeqd_fulldisk.py 2009-01-06 16:38:47 UTC (rev 6740)
@@ -0,0 +1,19 @@
+from mpl_toolkits.basemap import Basemap
+import numpy as np
+import matplotlib.pyplot as plt
+lon_0 = -105; lat_0 = 40
+m = Basemap(projection='aeqd',lat_0=lat_0,lon_0=lon_0)
+# fill background.
+m.drawmapboundary(fill_color='aqua')
+# draw coasts and fill continents.
+m.drawcoastlines(linewidth=0.5)
+m.fillcontinents(color='coral',lake_color='aqua')
+# 20 degree graticule.
+m.drawparallels(np.arange(-80,81,20))
+m.drawmeridians(np.arange(-180,180,20))
+# draw a black dot at the center.
+xpt, ypt = m(lon_0, lat_0)
+m.plot([xpt],[ypt],'ko')
+# draw the title.
+plt.title('Whole World Azimuthal Equidistant Projection')
+plt.savefig('aeqd_fulldisk.png')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jo...@us...> - 2009-01-06 08:07:20
|
Revision: 6739
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6739&view=rev
Author: jouni
Date: 2009-01-06 08:07:18 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
Create a PdfFile wrapper named PdfPages to act as the target of savefig
to avoid saving figures in png format onto the file-like PdfPages object.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/doc/api/api_changes.rst
trunk/matplotlib/examples/pylab_examples/multipage_pdf.py
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-01-05 18:11:47 UTC (rev 6738)
+++ trunk/matplotlib/CHANGELOG 2009-01-06 08:07:18 UTC (rev 6739)
@@ -1,3 +1,6 @@
+2009-01-06 Change user-visible multipage pdf object to PdfPages to
+ avoid accidents with the file-like PdfFile. - JKS
+
2009-01-05 Fix a bug in pdf usetex: allow using non-embedded fonts. - JKS
2009-01-05 optional use of preview.sty in usetex mode. - JJL
Modified: trunk/matplotlib/doc/api/api_changes.rst
===================================================================
--- trunk/matplotlib/doc/api/api_changes.rst 2009-01-05 18:11:47 UTC (rev 6738)
+++ trunk/matplotlib/doc/api/api_changes.rst 2009-01-06 08:07:18 UTC (rev 6739)
@@ -6,6 +6,10 @@
outward-facing API. If updating matplotlib breaks your scripts, this
list may help describe what changes may be necessary in your code.
+* You can now print several figures to one pdf file. See the docstrings
+ of the class :class:`matplotlib.backends.backend_pdf.PdfPages` for
+ more information.
+
* Removed configobj_ and `enthought.traits`_ packages, which are only
required by the experimental traited config and are somewhat out of
date. If needed, install them independently.
Modified: trunk/matplotlib/examples/pylab_examples/multipage_pdf.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/multipage_pdf.py 2009-01-05 18:11:47 UTC (rev 6738)
+++ trunk/matplotlib/examples/pylab_examples/multipage_pdf.py 2009-01-06 08:07:18 UTC (rev 6739)
@@ -1,14 +1,17 @@
+# This is a demo of creating a pdf file with several pages.
+
import numpy as np
import matplotlib
-from matplotlib.backends.backend_pdf import PdfFile
+from matplotlib.backends.backend_pdf import PdfPages
from pylab import *
-pdf = PdfFile('multipage_pdf.pdf')
+# Create the PdfPages object to which we will save the pages:
+pdf = PdfPages('multipage_pdf.pdf')
figure(figsize=(3,3))
plot(range(7), [3,1,4,1,5,9,2], 'r-o')
title('Page One')
-savefig(pdf, format='pdf')
+savefig(pdf, format='pdf') # note the format='pdf' argument!
close()
rc('text', usetex=True)
@@ -16,14 +19,15 @@
x = np.arange(0,5,0.1)
plot(x, np.sin(x), 'b-')
title('Page Two')
-savefig(pdf, format='pdf')
+pdf.savefig() # here's another way - or you could do pdf.savefig(1)
close()
rc('text', usetex=False)
-figure(figsize=(4,5))
+fig=figure(figsize=(4,5))
plot(x, x*x, 'ko')
title('Page Three')
-savefig(pdf, format='pdf')
+pdf.savefig(fig) # or you can pass a Figure object to pdf.savefig
close()
+# Remember to close the object - otherwise the file will not be usable
pdf.close()
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-05 18:11:47 UTC (rev 6738)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-06 08:07:18 UTC (rev 6739)
@@ -1882,7 +1882,64 @@
manager = FigureManagerPdf(canvas, num)
return manager
+class PdfPages(object):
+ """
+ A multi-page PDF file.
+ Use like this:
+
+ # Initialize:
+ pdf_pages = PdfPages('foo.pdf')
+
+ # As many times as you like, create a figure fig, then either:
+ fig.savefig(pdf_pages, format='pdf') # note the format argument!
+ # or:
+ pdf_pages.savefig(fig)
+
+ # Once you are done, remember to close the object:
+ pdf_pages.close()
+
+ (In reality PdfPages is a thin wrapper around PdfFile, in order to
+ avoid confusion when using savefig and forgetting the format
+ argument.)
+ """
+ __slots__ = ('_file',)
+
+ def __init__(self, filename):
+ """
+ Create a new PdfPages object that will be written to the file
+ named *filename*. The file is opened at once and any older
+ file with the same name is overwritten.
+ """
+ self._file = PdfFile(filename)
+
+ def close(self):
+ """
+ Finalize this object, making the underlying file a complete
+ PDF file.
+ """
+ self._file.close()
+ self._file = None
+
+ def savefig(self, figure=None, **kwargs):
+ """
+ Save the Figure instance *figure* to this file as a new page.
+ If *figure* is a number, the figure instance is looked up by
+ number, and if *figure* is None, the active figure is saved.
+ Any other keyword arguments are passed to Figure.savefig.
+ """
+ if isinstance(figure, Figure):
+ figure.savefig(self, format='pdf', **kwargs)
+ else:
+ if figure is None:
+ figureManager = Gcf.get_active()
+ else:
+ figureManager = Gcf.get_fig_manager(figure)
+ if figureManager is None:
+ raise ValueError, "No such figure: " + `figure`
+ else:
+ figureManager.canvas.figure.savefig(self, format='pdf')
+
class FigureCanvasPdf(FigureCanvasBase):
"""
The canvas the figure renders into. Calls the draw and print fig
@@ -1905,8 +1962,8 @@
image_dpi = kwargs.get('dpi', 72) # dpi to use for images
self.figure.set_dpi(72) # there are 72 pdf points to an inch
width, height = self.figure.get_size_inches()
- if isinstance(filename, PdfFile):
- file = filename
+ if isinstance(filename, PdfPages):
+ file = filename._file
else:
file = PdfFile(filename)
file.newPage(width, height)
@@ -1914,10 +1971,10 @@
width, height, 72, RendererPdf(file, image_dpi))
self.figure.draw(renderer)
renderer.finalize()
- if file != filename: # we opened the file
+ if isinstance(filename, PdfPages): # finish off this page
+ file.endStream()
+ else: # we opened the file above; now finish it off
file.close()
- else: # multipage file; just finish off the page
- file.endStream()
class FigureManagerPdf(FigureManagerBase):
pass
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jo...@us...> - 2009-01-05 18:11:55
|
Revision: 6738
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6738&view=rev
Author: jouni
Date: 2009-01-05 18:11:47 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
Remove extra line from backend_pdf.draw_tex
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-05 17:48:01 UTC (rev 6737)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2009-01-05 18:11:47 UTC (rev 6738)
@@ -1396,7 +1396,6 @@
pdfname = self.file.fontName(dvifont.texname)
if not self.file.dviFontInfo.has_key(dvifont.texname):
psfont = self.tex_font_mapping(dvifont.texname)
- fontfile = psfont.filename
self.file.dviFontInfo[dvifont.texname] = Bunch(
fontfile=psfont.filename,
basefont=psfont.psname,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|