本文整理汇总了Python中matplotlib.Figure方法的典型用法代码示例。如果您正苦于以下问题:Python matplotlib.Figure方法的具体用法?Python matplotlib.Figure怎么用?Python matplotlib.Figure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib
的用法示例。
在下文中一共展示了matplotlib.Figure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def run(self, fig):
"""
Run the exporter on the given figure
Parmeters
---------
fig : matplotlib.Figure instance
The figure to export
"""
# Calling savefig executes the draw() command, putting elements
# in the correct place.
if fig.canvas is None:
canvas = FigureCanvasAgg(fig)
fig.savefig(io.BytesIO(), format='png', dpi=fig.dpi)
if self.close_mpl:
import matplotlib.pyplot as plt
plt.close(fig)
self.crawl_fig(fig)
示例2: run
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def run(self, fig):
"""
Run the exporter on the given figure
Parmeters
---------
fig : matplotlib.Figure instance
The figure to export
"""
# Calling savefig executes the draw() command, putting elements
# in the correct place.
fig.savefig(io.BytesIO(), format='png', dpi=fig.dpi)
if self.close_mpl:
import matplotlib.pyplot as plt
plt.close(fig)
self.crawl_fig(fig)
示例3: fit
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def fit(self, figure):
"""
the main function to fit the parameters to the input figure
Parameters
----------
figure: matplotlib.figure.Figure object or matplotlib.AxesSubplot object
this function only proceed with one set of axes in the figure.
Returns
-------
matplotlib.figure.Figure object
"""
if str(type(figure)) == "<class 'matplotlib.axes._subplots.AxesSubplot'>":
ax = figure
figure = figure.figure
elif str(type(figure)) == "<class 'matplotlib.figure.Figure'>":
ax = figure.axes[0]
else:
msg = 'object must be a matplotlib.AxesSubplot or matplotlib.Figure object'
raise TypeError(msg)
if len(figure.axes) != 1:
msg = 'matplotlib.figure object includes more than one axes'
raise TypeError(msg)
ax.set_title(self.title)
ax.set_xlabel(self.xlabel)
ax.set_ylabel(self.ylabel)
ax.set_xlim(self.xlim[0], self.xlim[1])
ax.set_ylim(self.ylim[0], self.ylim[1])
ax.grid(color=self.grid_color, linestyle=self.grid_linestyle, linewidth=self.grid_linewidth)
ax.grid(self.grid)
return figure
示例4: plot
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def plot(self, dfx, x):
"""
the main function to plot based on the input dataframe and its header
Parameters
----------
dfx: pandas dataframe
the x axis data
x: string or integer, optional (default=0)
header or position of data in the dfx
Returns
-------
matplotlib.figure.Figure object
"""
# check data
if isinstance(x, str):
X = dfx[x].values
elif isinstance(x, int):
X = dfx.iloc[:, x].values
else:
msg = 'x must be string for the header or integer for the postion of data in the dfx'
raise TypeError(msg)
# instantiate figure
fig = plt.figure()
ax = fig.add_subplot(111)
tash = ax.hist(X, bins= self.bins, color=self.color, **self.kwargs)
return fig
示例5: interpolation_plot
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def interpolation_plot(data, title=None, ax_names=None):
"""Creates black and white interpolation plot
Creates a black and white interpolation plot from data, which must consist
of a 0/1 matrix for absence/presence of taxa in genes.
Parameters
----------
data : numpy.array
Single or multi-dimensional array with plot data.
title : str
Title of the plot.
ax_names : list
List with the labels for the x-axis (first element) and y-axis
(second element).
Returns
-------
fig : matplotlib.pyplot.Figure
Figure object of the plot.
_ : None
Placeholder for the legend object. Not used here but assures
consistency across other plotting methods.
_ : None
Placeholder for the table header list. Not used here but assures
consistency across other plotting methods.
"""
plt.rcParams["figure.figsize"] = (8, 6)
# Use ggpot style
plt.style.use("ggplot")
fig, ax = plt.subplots()
# Setting the aspect ratio proportional to the data
ar = float(len(data[0])) / float(len(data)) * .2
ax.imshow(data, interpolation="none", cmap="Greys", aspect=ar)
ax.grid(False)
return fig, None, None
示例6: outlier_densisty_dist
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import Figure [as 别名]
def outlier_densisty_dist(data, outliers, outliers_labels=None, ax_names=None,
title=None):
"""Creates a density distribution for outlier plots.
Parameters
----------
data : numpy.array
1D array containing data points.
outliers : numpy.array
1D array containing the outliers.
outliers_labels : list or numpy.array
1D array containing the labels for each outlier.
title : str
Title of the plot.
Returns
-------
fig : matplotlib.Figure
Figure object of the plot.
lgd : matplotlib.Legend
Legend object of the plot.
table : list
Table data in list format. Each item in the list corresponds to a
table row.
"""
plt.rcParams["figure.figsize"] = (8, 6)
fig, ax = plt.subplots()
# Create density function
sns.distplot(data, rug=True, hist=False, color="black")
# Plot outliers
ax.plot(outliers, np.zeros_like(outliers), "ro", clip_on=False,
label="Outliers")
# Create legend
lgd = ax.legend(frameon=True, loc=2, fancybox=True, shadow=True,
framealpha=.8, prop={"weight": "bold"})
if outliers_labels:
table = [[os.path.basename(x)] for x in outliers_labels]
else:
table = None
return fig, lgd, table