本文整理汇总了Python中matplotlib.pyplot.Axes方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.Axes方法的具体用法?Python pyplot.Axes怎么用?Python pyplot.Axes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.Axes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def plot_data(data):
t = np.arange(0, 29, 1)
file_name_number = 0
fig = plt.figure(frameon=False)
for group in data:
count = 30
while count <= (len(group)-5):
high = []
low = []
for item in group[count-30:count]:
high.append(item[0])
low.append(item[1])
file_name = r'\fig_' + str(file_name_number)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.plot(t, high[0:-1], 'b', t, low[0:-1], 'g')
fig.savefig(r'\figures' + file_name)
fig.clf()
file_name_number += 1
count += 1
print('Created %d files!' % file_name_number)
示例2: plot_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def plot_data(data):
t = np.arange(0, 29, 1)
file_name_number = 0
fig = plt.figure(frameon=False, figsize=(width, height))
for group in data:
count = 30
while count <= (len(group)-5):
high = []
low = []
for item in group[count-30:count]:
high.append(item[0])
low.append(item[1])
file_name = r'\fig_' + str(file_name_number)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.plot(t, high[0:-1], 'b', t, low[0:-1], 'g')
fig.savefig(r'\figures_v2' + file_name, dpi=100)
fig.clf()
file_name_number += 1
count += 1
print('Created %d files!' % file_name_number)
示例3: assert_is_valid_plot_return_object
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def assert_is_valid_plot_return_object(objs): # pragma: no cover
import matplotlib.pyplot as plt
if isinstance(objs, (pd.Series, np.ndarray)):
for el in objs.ravel():
msg = (
"one of 'objs' is not a matplotlib Axes instance, "
"type encountered {}".format(repr(type(el).__name__))
)
assert isinstance(el, (plt.Axes, dict)), msg
else:
msg = (
"objs is neither an ndarray of Artist instances nor a single "
"ArtistArtist instance, tuple, or dict, 'objs' is a {}".format(
repr(type(objs).__name__))
)
assert isinstance(objs, (plt.Artist, tuple, dict)), msg
示例4: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def plot(self, **kwargs):
"""Plot current quadtree
:param axes: Axes instance to plot in, defaults to None
:type axes: [:py:class:`matplotlib.Axes`], optional
:param figure: Figure instance to plot in, defaults to None
:type figure: [:py:class:`matplotlib.Figure`], optional
:param **kwargs: kwargs are passed into `plt.imshow`
:type **kwargs: dict
"""
self._initImagePlot(**kwargs)
self.data = self._quadtree.leaf_matrix_means
self.title = 'Quadtree Means'
self._addInfoText()
if self._show_plt:
plt.show()
示例5: _prepare_state_printing
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def _prepare_state_printing(self, ax: plt.Axes):
ys = [self.TEXT_Y_POSN_INITIAL + i * self.TEXT_Y_INCREMENT
for i in range(len(self.print_props))]
for prop, y in zip(self.print_props, ys):
label = str(prop.name)
ax.text(self.TEXT_X_POSN_LABEL, y, label, transform=ax.transAxes, **(self.LABEL_TEXT_KWARGS))
# print and store empty Text objects which we will rewrite each plot call
value_texts = []
dummy_msg = ''
for y in ys:
text = ax.text(self.TEXT_X_POSN_VALUE, y, dummy_msg, transform=ax.transAxes,
**(self.VALUE_TEXT_KWARGS))
value_texts.append(text)
self.value_texts = tuple(value_texts)
示例6: axes_object
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def axes_object(ax):
""" Checks if a value if an Axes. If None, a new one is created.
Both the figure and axes are returned (in that order).
"""
if ax is None:
ax = pyplot.gca()
fig = ax.figure
elif isinstance(ax, pyplot.Axes):
fig = ax.figure
else:
msg = "`ax` must be a matplotlib Axes instance or None"
raise ValueError(msg)
return fig, ax
示例7: show
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def show(plot_to_show):
"""Display a plot, either interactive or static.
Parameters
----------
plot_to_show: Output of a plotting command (matplotlib axis or bokeh figure)
The plot to show
Returns
-------
None
"""
if isinstance(plot_to_show, plt.Axes):
show_static()
elif isinstance(plot_to_show, bpl.Figure):
show_interactive(plot_to_show)
else:
raise ValueError(
"The type of ``plot_to_show`` was not valid, or not understood."
)
示例8: _write_annotations
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def _write_annotations(self, mesh: mpl_collections.Collection,
ax: plt.Axes) -> None:
"""Writes annotations to the center of cells. Internal."""
for path, facecolor in zip(mesh.get_paths(), mesh.get_facecolors()):
# Calculate the center of the cell, assuming that it is a square
# centered at (x=col, y=row).
vertices = path.vertices[:4]
row = int(round(np.mean([v[1] for v in vertices])))
col = int(round(np.mean([v[0] for v in vertices])))
annotation = self.annot_map.get((row, col), '')
if not annotation:
continue
face_luminance = relative_luminance(facecolor)
text_color = 'black' if face_luminance > 0.4 else 'white'
text_kwargs = dict(color=text_color, ha="center", va="center")
text_kwargs.update(self.annot_kwargs)
ax.text(col, row, annotation, **text_kwargs)
示例9: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def plot(self, ax: Optional[plt.Axes] = None,
**plot_kwargs: Any) -> plt.Axes:
"""Plots the average XEB fidelity vs the number of cycles.
Args:
ax: the plt.Axes to plot on. If not given, a new figure is created,
plotted on, and shown.
**plot_kwargs: Arguments to be passed to 'plt.Axes.plot'.
Returns:
The plt.Axes containing the plot.
"""
show_plot = not ax
if not ax:
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
num_cycles = [d.num_cycle for d in self.data]
fidelities = [d.xeb_fidelity for d in self.data]
ax.set_ylim([0, 1.1])
ax.plot(num_cycles, fidelities, 'ro-', **plot_kwargs)
ax.set_xlabel('Number of Cycles')
ax.set_ylabel('XEB Fidelity')
if show_plot:
fig.show()
return ax
示例10: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def plot(self, ax: Optional[plt.Axes] = None,
**plot_kwargs: Any) -> plt.Axes:
"""Plots the average ground state probability vs the number of
Cliffords in the RB study.
Args:
ax: the plt.Axes to plot on. If not given, a new figure is created,
plotted on, and shown.
**plot_kwargs: Arguments to be passed to 'plt.Axes.plot'.
Returns:
The plt.Axes containing the plot.
"""
show_plot = not ax
if not ax:
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
ax.set_ylim([0, 1])
ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro-', **plot_kwargs)
ax.set_xlabel(r"Number of Cliffords")
ax.set_ylabel('Ground State Probability')
if show_plot:
fig.show()
return ax
示例11: save_pic
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def save_pic(pic, path, exp):
if len(pic.shape) == 4:
pic = pic[0]
height = pic.shape[0]
width = pic.shape[1]
fig = plt.figure(frameon=False, figsize=(width, height))#, dpi=1)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
if exp.symmetrize:
pic = (pic + 1.) / 2.
if exp.dataset == 'mnist':
pic = pic[:, :, 0]
pic = 1. - pic
if exp.dataset == 'mnist':
ax.imshow(pic, cmap='Greys', interpolation='none')
else:
ax.imshow(pic, interpolation='none')
fig.savefig(path, dpi=1, format='png')
plt.close()
# if exp.dataset == 'mnist':
# pic = pic[:, :, 0]
# pic = 1. - pic
# ax = plt.imshow(pic, cmap='Greys', interpolation='none')
# else:
# ax = plt.imshow(pic, interpolation='none')
# ax.axes.get_xaxis().set_ticks([])
# ax.axes.get_yaxis().set_ticks([])
# ax.axes.set_xlim([0, width])
# ax.axes.set_ylim([height, 0])
# ax.axes.set_aspect(1)
# fig.savefig(path, format='png')
# plt.close()
示例12: assert_is_valid_plot_return_object
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def assert_is_valid_plot_return_object(objs):
import matplotlib.pyplot as plt
if isinstance(objs, (pd.Series, np.ndarray)):
for el in objs.ravel():
msg = ("one of 'objs' is not a matplotlib Axes instance, type "
"encountered {name!r}").format(name=el.__class__.__name__)
assert isinstance(el, (plt.Axes, dict)), msg
else:
assert isinstance(objs, (plt.Artist, tuple, dict)), (
'objs is neither an ndarray of Artist instances nor a '
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
.format(name=objs.__class__.__name__))
示例13: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def __init__(self, image, title="Initial problem"):
aspect_ratio = image.shape[0] / float(image.shape[1])
width = 8
height = width * aspect_ratio
fig = plt.figure(figsize=(width, height), frameon=False)
# Let image fill the figure
ax = plt.Axes(fig, [0., 0., 1., .9])
ax.set_axis_off()
fig.add_axes(ax)
self._current_image = ax.imshow(image, aspect="auto", animated=True)
self.show_fittest(image, title)
示例14: assert_is_valid_plot_return_object
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def assert_is_valid_plot_return_object(objs):
import matplotlib.pyplot as plt
if isinstance(objs, (pd.Series, np.ndarray)):
for el in objs.ravel():
msg = ('one of \'objs\' is not a matplotlib Axes instance, type '
'encountered {name!r}').format(name=el.__class__.__name__)
assert isinstance(el, (plt.Axes, dict)), msg
else:
assert isinstance(objs, (plt.Artist, tuple, dict)), \
('objs is neither an ndarray of Artist instances nor a '
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
).format(name=objs.__class__.__name__)
示例15: grouped_hist
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Axes [as 别名]
def grouped_hist(data, column=None, by=None, ax=None, bins=50, figsize=None,
layout=None, sharex=False, sharey=False, rot=90, grid=True,
**kwargs):
"""
Grouped histogram
Parameters
----------
data: Series/DataFrame
column: object, optional
by: object, optional
ax: axes, optional
bins: int, default 50
figsize: tuple, optional
layout: optional
sharex: boolean, default False
sharey: boolean, default False
rot: int, default 90
grid: bool, default True
kwargs: dict, keyword arguments passed to matplotlib.Axes.hist
Returns
-------
axes: collection of Matplotlib Axes
"""
def plot_group(group, ax):
ax.hist(group.dropna().values, bins=bins, **kwargs)
fig, axes = _grouped_plot(plot_group, data, column=column,
by=by, sharex=sharex, sharey=sharey,
figsize=figsize, layout=layout, rot=rot)
fig.subplots_adjust(bottom=0.15, top=0.9, left=0.1, right=0.9,
hspace=0.5, wspace=0.3)
return axes