#5128: matplotlib Graphics() wrapper
-------------------------+--------------------------------------------------
Reporter: jason | Owner: was
Type: enhancement | Status: new
Priority: major | Milestone: sage-3.3
Component: graphics | Keywords:
-------------------------+--------------------------------------------------
This provides an easy way to make a matplotlib image and combine it with
other Graphics() objects:
{{{
class Matplotlib_Primitive(GraphicPrimitive):
"""
Primitive class that initializes the
matrix_plot graphics type
"""
def __init__(self, artist, options=None):
self.artist = artist
GraphicPrimitive.__init__(self, options)
def get_minmax_data(self):
"""
Returns a dictionary with the bounding box data.
EXAMPLES:
sage: m =
matrix_plot(matrix([[1,3,5,1],[2,4,5,6],[1,3,5,7]]))[0]
sage: list(sorted(m.get_minmax_data().items()))
[('xmax', 4), ('xmin', 0), ('ymax', 3), ('ymin', 0)]
"""
return dict(zip(['xmin', 'xmax', 'ymax', 'ymin'],
self.artist.get_extent()))
def _allowed_options(self):
return {}
def _repr_(self):
return "MatrixPlot defined by a %s x %s data
grid"%(self.xy_array_row, self.xy_array_col)
def _render_on_subplot(self, subplot):
subplot.add_artist(self.artist)
def matplotlib_plot(mat):
from sage.plot.plot import Graphics
g = Graphics()
g.add_primitive(Matplotlib_Primitive(mat))
return g
}}}
Example use:
{{{
A=random_matrix(RDF,100)
A.numpy()
import pylab
import numpy
B=A.numpy().astype(float)
im = pylab.imshow(B/numpy.max(B), origin='upper',alpha=0.6)
matplotlib_plot(im)+polygon([[0,10],[10,0],[20,40]])
}}}
This just needs to be put in a file in the plot/ directory and an entry
added to all.py.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5128>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---