本文整理汇总了Python中matplotlib.figure.Figure.add_host_subplot方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.add_host_subplot方法的具体用法?Python Figure.add_host_subplot怎么用?Python Figure.add_host_subplot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.add_host_subplot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Qt4MplCanvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import add_host_subplot [as 别名]
class Qt4MplCanvas(FigureCanvas):
""" A customized Qt widget for matplotlib figure.
It can be used to replace GraphicsView of QtGui
"""
def __init__(self, parent):
""" Initialization
"""
# from mpl_toolkits.axes_grid1 import host_subplot
# import mpl_toolkits.axisartist as AA
# import matplotlib.pyplot as plt
# Instantiating matplotlib Figure
self.fig = Figure()
self.fig.patch.set_facecolor('white')
if True:
self.axes = self.fig.add_subplot(111) # return: matplotlib.axes.AxesSubplot
self.axes2 = None
else:
self.axes = self.fig.add_host_subplot(111)
# Initialize parent class and set parent
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
# Set size policy to be able to expanding and resizable with frame
FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
# Variables to manage all lines/subplot
self._lineDict = {}
self._lineIndex = 0
# legend and color bar
self._colorBar = None
return
def add_plot_1d(self, vec_x, vec_y, y_err=None, color=None, label="", x_label=None, y_label=None,
marker=None, line_style=None, line_width=1):
"""
:param vec_x: numpy array X
:param vec_y: numpy array Y
:param y_err:
:param color:
:param label:
:param x_label:
:param y_label:
:param marker:
:param line_style:
:param line_width:
:return: new key
"""
# Check input
if isinstance(vec_x, np.ndarray) is False or isinstance(vec_y, np.ndarray) is False:
raise NotImplementedError('Input vec_x or vec_y for addPlot() must be numpy.array.')
plot_error = y_err is not None
if plot_error is True:
if isinstance(y_err, np.ndarray) is False:
raise NotImplementedError('Input y_err must be either None or numpy.array.')
if len(vec_x) != len(vec_y):
raise NotImplementedError('Input vec_x and vec_y must have same size.')
if plot_error is True and len(y_err) != len(vec_x):
raise NotImplementedError('Input vec_x, vec_y and y_error must have same size.')
# Hold previous data
self.axes.hold(True)
# process inputs and defaults
if color is None:
color = (0,1,0,1)
if marker is None:
marker = 'o'
if line_style is None:
line_style = '-'
# color must be RGBA (4-tuple)
if plot_error is False:
print "[DB] line_style = ", line_style, "line_width = ", line_width, "marker = ", marker, "color = ", color
r = self.axes.plot(vec_x, vec_y, color=color, marker=marker, linestyle=line_style,
label=label, linewidth=line_width)
# return: list of matplotlib.lines.Line2D object
else:
r = self.axes.errorbar(vec_x, vec_y, yerr=y_err, color=color, marker=marker, linestyle=line_style,
label=label, linewidth=line_width)
self.axes.set_aspect('auto')
# set x-axis and y-axis label
if x_label is not None:
self.axes.set_xlabel(x_label, fontsize=20)
if y_label is not None:
self.axes.set_ylabel(y_label, fontsize=20)
# set/update legend
self._setupLegend()
# Register
#.........这里部分代码省略.........