本文整理匯總了Python中matplotlib.axes.Axes.plot方法的典型用法代碼示例。如果您正苦於以下問題:Python Axes.plot方法的具體用法?Python Axes.plot怎麽用?Python Axes.plot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.axes.Axes
的用法示例。
在下文中一共展示了Axes.plot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_steps_mid
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_steps_mid(ax):
ax.plot([0, 1], [0, 1], drawstyle="steps-mid")
ax.set(xlim=(-1, 2), ylim=(-1, 2))
cursor = mplcursors.cursor()
_process_event("__mouse_click__", ax, (0, 1), 1)
assert len(cursor.selections) == 0
_process_event("__mouse_click__", ax, (1, 0), 1)
assert len(cursor.selections) == 0
_process_event("__mouse_click__", ax, (.25, 0), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, .25, 0))
_process_event("__mouse_click__", ax, (.5, .5), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, .5, .5))
_process_event("__mouse_click__", ax, (.75, 1), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, .75, 1))
示例2: test_move
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_move(ax, plotter):
plotter(ax, [0, 1, 2], [0, 1, np.nan])
cursor = mplcursors.cursor()
# Nothing happens with no cursor.
_process_event("key_press_event", ax, (.123, .456), "shift+left")
assert len(cursor.selections) == 0
# Now we move the cursor left or right.
if plotter in [Axes.plot, Axes.errorbar]:
_process_event("__mouse_click__", ax, (.5, .5), 1)
assert tuple(cursor.selections[0].target) == approx((.5, .5))
_process_event("key_press_event", ax, (.123, .456), "shift+up")
_process_event("key_press_event", ax, (.123, .456), "shift+left")
elif plotter is Axes.scatter:
_process_event("__mouse_click__", ax, (0, 0), 1)
_process_event("key_press_event", ax, (.123, .456), "shift+up")
assert tuple(cursor.selections[0].target) == (0, 0)
assert cursor.selections[0].target.index == 0
_process_event("key_press_event", ax, (.123, .456), "shift+right")
assert tuple(cursor.selections[0].target) == (1, 1)
assert cursor.selections[0].target.index == 1
# Skip through nan.
_process_event("key_press_event", ax, (.123, .456), "shift+right")
assert tuple(cursor.selections[0].target) == (0, 0)
assert cursor.selections[0].target.index == 0
示例3: test_autoalign
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_autoalign(ax):
ax.plot([0, 1])
cursor = mplcursors.cursor()
cursor.connect(
"add", lambda sel: sel.annotation.set(position=(-10, 0)))
_process_event("__mouse_click__", ax, (.5, .5), 1)
sel, = cursor.selections
assert (sel.annotation.get_ha() == "right"
and sel.annotation.get_va() == "center")
cursor.remove_selection(sel)
cursor.connect(
"add", lambda sel: sel.annotation.set(ha="center", va="bottom"))
_process_event("__mouse_click__", ax, (.5, .5), 1)
sel, = cursor.selections
assert (sel.annotation.get_ha() == "center"
and sel.annotation.get_va() == "bottom")
示例4: test_keys
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_keys(ax):
ax.plot([0, 1])
cursor = mplcursors.cursor(multiple=True)
_process_event("__mouse_click__", ax, (.3, .3), 1)
# Toggle visibility.
_process_event("key_press_event", ax, (.123, .456), "v")
assert not cursor.selections[0].annotation.get_visible()
_process_event("key_press_event", ax, (.123, .456), "v")
assert cursor.selections[0].annotation.get_visible()
# Disable the cursor.
_process_event("key_press_event", ax, (.123, .456), "e")
assert not cursor.enabled
# (Adding becomes inactive.)
_process_event("__mouse_click__", ax, (.6, .6), 1)
assert len(cursor.selections) == 1
# (Removing becomes inactive.)
ax.figure.canvas.draw()
_process_event(*_get_remove_args(cursor.selections[0]))
assert len(cursor.selections) == 1
# Reenable it.
_process_event("key_press_event", ax, (.123, .456), "e")
assert cursor.enabled
_process_event(*_get_remove_args(cursor.selections[0]))
assert len(cursor.selections) == 0
示例5: test_multiple_figures
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_multiple_figures(ax):
ax1 = ax
_, ax2 = plt.subplots()
ax1.plot([0, 1])
ax2.plot([0, 1])
cursor = mplcursors.cursor([ax1, ax2], multiple=True)
# Add something on the first axes.
_process_event("__mouse_click__", ax1, (.5, .5), 1)
assert len(cursor.selections) == 1
assert len(ax1.texts) == 1
assert len(ax2.texts) == 0
# Right-clicking on the second axis doesn't remove it.
remove_args = [*_get_remove_args(cursor.selections[0])]
remove_args[remove_args.index(ax1)] = ax2
_process_event(*remove_args)
assert len(cursor.selections) == 1
assert len(ax1.texts) == 1
assert len(ax2.texts) == 0
# Remove it, add something on the second.
_process_event(*_get_remove_args(cursor.selections[0]))
_process_event("__mouse_click__", ax2, (.5, .5), 1)
assert len(cursor.selections) == 1
assert len(ax1.texts) == 0
assert len(ax2.texts) == 1
示例6: draw
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def draw():
"""
Redraw the current figure.
This is used in interactive mode to update a figure that
has been altered using one or more plot object method calls;
it is not needed if figure modification is done entirely
with pyplot functions, if a sequence of modifications ends
with a pyplot function, or if matplotlib is in non-interactive
mode and the sequence of modifications ends with :func:`show` or
:func:`savefig`.
A more object-oriented alternative, given any
:class:`~matplotlib.figure.Figure` instance, :attr:`fig`, that
was created using a :mod:`~matplotlib.pyplot` function, is::
fig.canvas.draw()
"""
get_current_fig_manager().canvas.draw()
示例7: gca
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def gca(**kwargs):
"""
Return the current axis instance. This can be used to control
axis properties either using set or the
:class:`~matplotlib.axes.Axes` methods, for example, setting the
xaxis range::
plot(t,s)
set(gca(), 'xlim', [0,10])
or::
plot(t,s)
a = gca()
a.set_xlim([0,10])
"""
ax = gcf().gca(**kwargs)
return ax
# More ways of creating axes:
示例8: polar
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def polar(*args, **kwargs):
"""
Make a polar plot.
call signature::
polar(theta, r, **kwargs)
Multiple *theta*, *r* arguments are supported, with format
strings, as in :func:`~matplotlib.pyplot.plot`.
"""
ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
draw_if_interactive()
return ret
示例9: plot
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def plot(*args, **kwargs):
ax = gca()
# allow callers to override the hold state by passing hold=True|False
washold = ax.ishold()
hold = kwargs.pop('hold', None)
if hold is not None:
ax.hold(hold)
try:
ret = ax.plot(*args, **kwargs)
draw_if_interactive()
finally:
ax.hold(washold)
return ret
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
示例10: polar
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def polar(*args, **kwargs):
"""
Make a polar plot.
call signature::
polar(theta, r, **kwargs)
Multiple *theta*, *r* arguments are supported, with format
strings, as in :func:`~matplotlib.pyplot.plot`.
"""
# If an axis already exists, check if it has a polar projection
if gcf().get_axes():
if not isinstance(gca(), PolarAxes):
warnings.warn('Trying to create polar plot on an axis that does '
'not have a polar projection.')
ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
return ret
示例11: polar
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def polar(*args, **kwargs):
"""
Make a polar plot.
call signature::
polar(theta, r, **kwargs)
Multiple *theta*, *r* arguments are supported, with format
strings, as in :func:`~matplotlib.pyplot.plot`.
"""
# If an axis already exists, check if it has a polar projection
if gcf().get_axes():
if not isinstance(gca(), PolarAxes):
cbook._warn_external('Trying to create polar plot on an axis '
'that does not have a polar projection.')
ax = gca(polar=True)
ret = ax.plot(*args, **kwargs)
return ret
示例12: test_steps_pre
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_steps_pre(ax):
ax.plot([0, 1], [0, 1], drawstyle="steps-pre")
ax.set(xlim=(-1, 2), ylim=(-1, 2))
cursor = mplcursors.cursor()
_process_event("__mouse_click__", ax, (1, 0), 1)
assert len(cursor.selections) == 0
_process_event("__mouse_click__", ax, (0, .5), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, 0, .5))
_process_event("__mouse_click__", ax, (.5, 1), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, .5, 1))
示例13: test_steps_post
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_steps_post(ax):
ax.plot([0, 1], [0, 1], drawstyle="steps-post")
ax.set(xlim=(-1, 2), ylim=(-1, 2))
cursor = mplcursors.cursor()
_process_event("__mouse_click__", ax, (0, 1), 1)
assert len(cursor.selections) == 0
_process_event("__mouse_click__", ax, (.5, 0), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, .5, 0))
_process_event("__mouse_click__", ax, (1, .5), 1)
index = cursor.selections[0].target.index
assert (index.int, index.x, index.y) == approx((0, 1, .5))
示例14: test_line_single_point
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_line_single_point(ax, ls):
ax.plot(0, ls)
ax.set(xlim=(-1, 1), ylim=(-1, 1))
cursor = mplcursors.cursor()
_process_event("__mouse_click__", ax, (.001, .001), 1)
assert len(cursor.selections) == len(ax.texts) == (ls == "o")
if cursor.selections:
assert tuple(cursor.selections[0].target) == (0, 0)
示例15: test_nan
# 需要導入模塊: from matplotlib.axes import Axes [as 別名]
# 或者: from matplotlib.axes.Axes import plot [as 別名]
def test_nan(ax, plot_args, click, targets):
ax.plot(*plot_args)
cursor = mplcursors.cursor()
_process_event("__mouse_click__", ax, click, 1)
assert len(cursor.selections) == len(ax.texts) == len(targets)
for sel, target in zip(cursor.selections, targets):
assert sel.target == approx(target)