本文整理汇总了Python中matplotlib.pyplot.twinx方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.twinx方法的具体用法?Python pyplot.twinx怎么用?Python pyplot.twinx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.twinx方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_twin_axis_locaters_formatters
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twin_axis_locaters_formatters():
vals = np.linspace(0, 1, num=5, endpoint=True)
locs = np.sin(np.pi * vals / 2.0)
majl = plt.FixedLocator(locs)
minl = plt.FixedLocator([0.1, 0.2, 0.3])
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ax1.plot([0.1, 100], [0, 1])
ax1.yaxis.set_major_locator(majl)
ax1.yaxis.set_minor_locator(minl)
ax1.yaxis.set_major_formatter(plt.FormatStrFormatter('%08.2lf'))
ax1.yaxis.set_minor_formatter(plt.FixedFormatter(['tricks', 'mind',
'jedi']))
ax1.xaxis.set_major_locator(plt.LinearLocator())
ax1.xaxis.set_minor_locator(plt.FixedLocator([15, 35, 55, 75]))
ax1.xaxis.set_major_formatter(plt.FormatStrFormatter('%05.2lf'))
ax1.xaxis.set_minor_formatter(plt.FixedFormatter(['c', '3', 'p', 'o']))
ax2 = ax1.twiny()
ax3 = ax1.twinx()
示例2: test_twinx_cla
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twinx_cla():
fig, ax = plt.subplots()
ax2 = ax.twinx()
ax3 = ax2.twiny()
plt.draw()
assert not ax2.xaxis.get_visible()
assert not ax2.patch.get_visible()
ax2.cla()
ax3.cla()
assert not ax2.xaxis.get_visible()
assert not ax2.patch.get_visible()
assert ax2.yaxis.get_visible()
assert ax3.xaxis.get_visible()
assert not ax3.patch.get_visible()
assert not ax3.yaxis.get_visible()
assert ax.xaxis.get_visible()
assert ax.patch.get_visible()
assert ax.yaxis.get_visible()
示例3: shared_axis_remover
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def shared_axis_remover(request):
def _helper_x(ax):
ax2 = ax.twinx()
ax2.remove()
ax.set_xlim(0, 15)
r = ax.xaxis.get_major_locator()()
assert r[-1] > 14
def _helper_y(ax):
ax2 = ax.twiny()
ax2.remove()
ax.set_ylim(0, 15)
r = ax.yaxis.get_major_locator()()
assert r[-1] > 14
return {"x": _helper_x, "y": _helper_y}[request.param]
示例4: _fitted_E_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def _fitted_E_plot(d, i=0, F=1, no_E=False, ax=None, show_model=True,
verbose=False, two_gauss_model=False, lw=2.5, color='k',
alpha=0.5, fillcolor=None):
"""Plot a fitted model overlay on a FRET histogram."""
if ax is None:
ax2 = gca()
else:
ax2 = plt.twinx(ax=ax)
ax2.grid(False)
if d.fit_E_curve and show_model:
x = r_[-0.2:1.21:0.002]
y = d.fit_E_model(x, d.fit_E_res[i, :])
scale = F*d.fit_E_model_F[i]
if two_gauss_model:
assert d.fit_E_res.shape[1] > 2
if d.fit_E_res.shape[1] == 5:
m1, s1, m2, s2, a1 = d.fit_E_res[i, :]
a2 = (1-a1)
elif d.fit_E_res.shape[1] == 6:
m1, s1, a1, m2, s2, a2 = d.fit_E_res[i, :]
y1 = a1*normpdf(x, m1, s1)
y2 = a2*normpdf(x, m2, s2)
ax2.plot(x, scale*y1, ls='--', lw=lw, alpha=alpha, color=color)
ax2.plot(x, scale*y2, ls='--', lw=lw, alpha=alpha, color=color)
if fillcolor is None:
ax2.plot(x, scale*y, lw=lw, alpha=alpha, color=color)
else:
ax2.fill_between(x, scale*y, lw=lw, alpha=alpha, edgecolor=color,
facecolor=fillcolor, zorder=10)
if verbose:
print('Fit Integral:', np.trapz(scale*y, x))
ax2.axvline(d.E_fit[i], lw=3, color=red, ls='--', alpha=0.6)
xtext = 0.6 if d.E_fit[i] < 0.6 else 0.2
if d.nch > 1 and not no_E:
ax2.text(xtext, 0.81, "CH%d: $E_{fit} = %.3f$" % (i+1, d.E_fit[i]),
transform=gca().transAxes, fontsize=16,
bbox=dict(boxstyle='round', facecolor='#dedede', alpha=0.5))
示例5: test_twinx_axis_scales
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twinx_axis_scales():
x = np.array([0, 0.5, 1])
y = 0.5 * x
x2 = np.array([0, 1, 2])
y2 = 2 * x2
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1), autoscalex_on=False, autoscaley_on=False)
ax.plot(x, y, color='blue', lw=10)
ax2 = plt.twinx(ax)
ax2.plot(x2, y2, 'r--', lw=5)
ax.margins(0, 0)
ax2.margins(0, 0)
示例6: test_twin_inherit_autoscale_setting
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twin_inherit_autoscale_setting():
fig, ax = plt.subplots()
ax_x_on = ax.twinx()
ax.set_autoscalex_on(False)
ax_x_off = ax.twinx()
assert ax_x_on.get_autoscalex_on()
assert not ax_x_off.get_autoscalex_on()
ax_y_on = ax.twiny()
ax.set_autoscaley_on(False)
ax_y_off = ax.twiny()
assert ax_y_on.get_autoscaley_on()
assert not ax_y_off.get_autoscaley_on()
示例7: test_subplot_key_hash
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_subplot_key_hash():
ax = plt.subplot(np.float64(5.5), np.int64(1), np.float64(1.2))
ax.twinx()
assert ax.get_subplotspec().get_geometry() == (5, 1, 0, 0)
示例8: test_twin_spines_on_top
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twin_spines_on_top():
matplotlib.rcParams['axes.linewidth'] = 48.0
matplotlib.rcParams['lines.linewidth'] = 48.0
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
data = np.array([[1000, 1100, 1200, 1250],
[310, 301, 360, 400]])
ax2 = ax1.twinx()
ax1.plot(data[0], data[1]/1E3, color='#BEAED4')
ax1.fill_between(data[0], data[1]/1E3, color='#BEAED4', alpha=.8)
ax2.plot(data[0], data[1]/1E3, color='#7FC97F')
ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5)
# Reuse testcase from above for a labeled data test
data = {"i": data[0], "j": data[1]/1E3}
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ax2 = ax1.twinx()
ax1.plot("i", "j", color='#BEAED4', data=data)
ax1.fill_between("i", "j", color='#BEAED4', alpha=.8, data=data)
ax2.plot("i", "j", color='#7FC97F', data=data)
ax2.fill_between("i", "j", color='#7FC97F', alpha=.5, data=data)
示例9: test_twin_with_aspect
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twin_with_aspect(twin):
fig, ax = plt.subplots()
# test twinx or twiny
ax_twin = getattr(ax, 'twin{}'.format(twin))()
ax.set_aspect(5)
ax_twin.set_aspect(2)
assert_array_equal(ax.bbox.extents,
ax_twin.bbox.extents)
示例10: test_twinx_knows_limits
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def test_twinx_knows_limits():
fig, ax = plt.subplots()
ax.axvspan(1, 2)
xtwin = ax.twinx()
xtwin.plot([0, 0.5], [1, 2])
# control axis
fig2, ax2 = plt.subplots()
ax2.axvspan(1, 2)
ax2.plot([0, 0.5], [1, 2])
assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)
示例11: buVsTime
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import twinx [as 别名]
def buVsTime(reactor, scalars):
r"""
produces a burnup and DPA vs. time plot for this case
Will add a second axis containing DPA if the scalar column maxDPA exists.
Parameters
----------
scalars : dict
Scalar values for this case
"""
plt.figure()
try:
plt.plot(scalars["time"], scalars["maxBuI"], ".-", label="Driver")
except ValueError:
runLog.warning(
"Incompatible axis length in burnup plot. Time has {0}, bu has {1}. Skipping"
"".format(len(scalars["time"]), len(scalars["maxBuI"]))
)
plt.close(1)
return
plt.plot(scalars["time"], scalars["maxBuF"], ".-", label="Feed")
plt.xlabel("Time (yr)")
plt.ylabel("BU (%FIMA)")
plt.grid(color="0.70")
plt.legend(loc="lower left")
title = "Maximum burnup"
if scalars["maxDPA"]:
plt.twinx()
plt.plot(scalars["time"], scalars["maxDPA"], "r--", label="dpa")
plt.legend(loc="lower right")
plt.ylabel("dpa")
title += " and DPA"
title += " for " + reactor.name
plt.title(title)
plt.legend(loc="lower right")
figName = reactor.name + ".bu." + settings.getMasterCs()["outputFileExtension"]
plt.savefig(figName)
plt.close(1)
report.setData("Burnup Plot", os.path.abspath(figName), report.BURNUP_PLOT)