本文整理汇总了Python中matplotlib.backends.backend_agg.FigureCanvasAgg.get_supported_filetypes方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasAgg.get_supported_filetypes方法的具体用法?Python FigureCanvasAgg.get_supported_filetypes怎么用?Python FigureCanvasAgg.get_supported_filetypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_agg.FigureCanvasAgg
的用法示例。
在下文中一共展示了FigureCanvasAgg.get_supported_filetypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Chart
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_supported_filetypes [as 别名]
class Chart(object):
"""
Simple and clean facade to Matplotlib's plotting API.
A chart instance abstracts a plotting device, on which one or
multiple related plots can be drawn. Charts can be exported as images, or
visualized interactively. Each chart instance will always open in its own
GUI window, and this window will never block the execution of the rest of
the program, or interfere with other L{Chart}s.
The GUI can be safely opened in the background and closed infinite number
of times, as long as the client program is still running.
By default, a chart contains a single plot:
>>> chart.plot
matplotlib.axes.AxesSubplot
>>> chart.plot.hist(...)
If C{rows} and C{columns} are defined, the chart will contain
C{rows} x C{columns} number of plots (equivalent to MPL's sub-plots).
Each plot can be assessed by its index:
>>> chart.plots[0]
first plot
or by its position in the grid:
>>> chart.plots[0, 1]
plot at row=0, column=1
@param number: chart number; by default this a L{Chart.AUTONUMBER}
@type number: int or None
@param title: chart master title
@type title: str
@param rows: number of rows in the chart window
@type rows: int
@param columns: number of columns in the chart window
@type columns: int
@note: additional arguments are passed directly to Matplotlib's Figure
constructor.
"""
AUTONUMBER = None
_serial = 0
def __init__(self, number=None, title='', rows=1, columns=1, backend=Backends.WX_WIDGETS, *fa, **fk):
if number == Chart.AUTONUMBER:
Chart._serial += 1
number = Chart._serial
if rows < 1:
rows = 1
if columns < 1:
columns = 1
self._rows = int(rows)
self._columns = int(columns)
self._number = int(number)
self._title = str(title)
self._figure = Figure(*fa, **fk)
self._figure._figure_number = self._number
self._figure.suptitle(self._title)
self._beclass = backend
self._hasgui = False
self._plots = PlotsCollection(self._figure, self._rows, self._columns)
self._canvas = FigureCanvasAgg(self._figure)
formats = [ (f.upper(), f) for f in self._canvas.get_supported_filetypes() ]
self._formats = csb.core.Enum.create('OutputFormats', **dict(formats))
def __getitem__(self, i):
if i in self._plots:
return self._plots[i]
else:
raise KeyError('No such plot number: {0}'.format(i))
def __enter__(self):
return self
def __exit__(self, *a, **k):
self.dispose()
@property
def _backend(self):
return Backend.get(self._beclass, started=True)
@property
def _backend_started(self):
return Backend.query(self._beclass)
@property
def title(self):
"""
Chart title
@rtype: str
"""
#.........这里部分代码省略.........
示例2: the
# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_supported_filetypes [as 别名]
class ReducePyMatplotlibHistogram: # pylint: disable=R0903
"""
@class ReducePyMatplotlibHistogram.PyMatplotlibHistogram is
a base class for classes that create histograms using matplotlib.
Histograms are output as JSON documents of form:
@verbatim
{"image": {"keywords": [...list of image keywords...],
"description":"...a description of the image...",
"tag": TAG,
"image_type": "eps",
"data": "...base 64 encoded image..."}}
@endverbatim
"TAG" is specified by the sub-class. If "histogram_auto_number"
(see below) is "true" then the TAG will have a number N appended
where N means that the histogram was produced as a consequence of
the (N + 1)th spill processed by the worker. The number will be
zero-padded to form a six digit string e.g. "00000N". If
"histogram_auto_number" is false then no such number is appended.
In cases where a spill is input that contains errors (e.g. is
badly formatted or is missing the data needed to update a
histogram) then a spill is output which is just the input spill
with an "errors" field containing the error e.g.
@verbatim
{"errors": {..., "bad_json_document": "unable to do json.loads on input"}}
{"errors": {..., "...": "..."}}
@endverbatim
The caller can configure the worker and specify:
-Image type ("histogram_image_type"). Must be one of those
supported by matplot lib (currently "svg", "ps", "emf", "rgba",
"raw", "svgz", "pdf", "eps", "png"). Default: "eps".
-Auto-number ("histogram_auto_number"). Default: false. Flag
that determines if the image tag (see above) has the spill count
appended to it or not.
-Sub-classes may support additional configuration parameter
Sub-classes must override:
-_configure_at_birth - to extract any additional
sub-class-specific configuration from data cards.
-_update_histograms. This checks that a spill has the data
necessary to update any histograms then creates JSON documents in
the format described above.
-_cleanup_at_death - to do any sub-class-specific cleanup.
"""
def __init__(self):
"""
Set initial attribute values.
@param self Object reference.
"""
# matplotlib histogram - for validation.
figure = Figure(figsize=(6, 6))
self.__histogram = FigureCanvas(figure)
self.spill_count = 0 # Number of spills processed to date.
self.image_type = "eps"
self.auto_number = False
def birth(self, config_json):
"""
Configure worker from data cards. If "image_type" is not
in those supported then a ValueError is thrown.
@param self Object reference.
@param config_json JSON document string.
@returns True if configuration succeeded.
"""
config_doc = json.loads(config_json)
key = "histogram_auto_number"
if key in config_doc:
self.auto_number = config_doc[key]
key = "histogram_image_type"
if key in config_doc:
self.image_type = config_doc[key]
else:
self.image_type = "eps"
if self.image_type not in \
self.__histogram.get_supported_filetypes().keys():
error = "Unsupported histogram image type: %s Expect one of %s" \
% (self.image_type,
self.__histogram.get_supported_filetypes().keys())
raise ValueError(error)
self.spill_count = 0
# Do sub-class-specific configuration.
return self._configure_at_birth(config_doc)
def _configure_at_birth(self, config_doc):
"""
Perform sub-class-specific configuration from data cards.
Sub-classes must define this function.
#.........这里部分代码省略.........