本文整理汇总了Python中mpl_toolkits.axes_grid1.inset_locator.inset_axes方法的典型用法代码示例。如果您正苦于以下问题:Python inset_locator.inset_axes方法的具体用法?Python inset_locator.inset_axes怎么用?Python inset_locator.inset_axes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.axes_grid1.inset_locator
的用法示例。
在下文中一共展示了inset_locator.inset_axes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_plain_axes
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def test_plain_axes(self):
# supplied ax itself is a SubplotAxes, but figure contains also
# a plain Axes object (GH11556)
fig, ax = self.plt.subplots()
fig.add_axes([0.2, 0.2, 0.2, 0.2])
Series(rand(10)).plot(ax=ax)
# suppliad ax itself is a plain Axes, but because the cmap keyword
# a new ax is created for the colorbar -> also multiples axes (GH11520)
df = DataFrame({'a': randn(8), 'b': randn(8)})
fig = self.plt.figure()
ax = fig.add_axes((0, 0, 1, 1))
df.plot(kind='scatter', ax=ax, x='a', y='b', c='a', cmap='hsv')
# other examples
fig, ax = self.plt.subplots()
from mpl_toolkits.axes_grid1 import make_axes_locatable
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
Series(rand(10)).plot(ax=ax)
Series(rand(10)).plot(ax=cax)
fig, ax = self.plt.subplots()
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
iax = inset_axes(ax, width="30%", height=1., loc=3)
Series(rand(10)).plot(ax=ax)
Series(rand(10)).plot(ax=iax)
示例2: set_colorbar
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def set_colorbar(smp, ax, orientation="vertical", labelsize=None):
cax = inset_axes(ax, width="2%", height="30%", loc=4, borderpad=0)
cb = pl.colorbar(smp, orientation=orientation, cax=cax)
cb.set_alpha(1)
cb.ax.tick_params(labelsize=labelsize)
cb.draw_all()
cb.locator = MaxNLocator(nbins=3, integer=True)
cb.update_ticks()
示例3: set_colorbar
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def set_colorbar(ax):
"""https://matplotlib.org/3.1.0/gallery/axes_grid1/demo_colorbar_with_inset_locator.html"""
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
axins = inset_axes(ax,
width="2.5%", # width = 5% of parent_bbox width
height="20%", # height : 50%
# loc='lower left',
# bbox_to_anchor=(1.05, 0., 1, 1),
# bbox_transform=ax.transAxes,
# borderpad=0,
)
return axins
示例4: add_colorbar
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def add_colorbar(powers_ax, im, cb_ticks=[], cb_ticks_font_size=12):
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
axins = inset_axes(powers_ax, width="5%", height="100%", loc=5,
bbox_to_anchor=(1.15, 0, 1, 1), bbox_transform=powers_ax.transAxes)
cb = plt.colorbar(im, cax=axins)
if cb_ticks != []:
cb.set_ticks(cb_ticks)
cb.ax.tick_params(labelsize=cb_ticks_font_size)
cb.ax.set_ylabel('dBHZ Z-Score', color='black', fontsize=cb_ticks_font_size)
示例5: mcolorbar
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def mcolorbar(imgh, ax, location="horizontal", width="5%", height="100%", offset="-15%", vticks=[], ticksize=10, label_offset="5", label="", labelsize=10):
"""
Add a multiple colormap colorbar to a plot.
Parameters
----------
imgh : list of image hangle returned from contour or img funtions
ax : current Axes instance, usually ax = plt.gca()
location : horizontal or vertical
width : in percentage
height : in percentage
offset : offset from the main plot in percentage
ticksize : tick size
vticks : tick value labels
labelsize : label size
label : colorbar label
label_offset : offset from the main plot in percentage
"""
bmargin=(1.0-float(height.strip('%'))/100.0)*0.5
fheight = 1.0/len(imgh)
cheight_float = (1.0-2.0*bmargin)*fheight
cheight = "%.2f%%" % (cheight_float*100.0)
offset=float(offset.strip('%'))/100.0
label_offset=float(label_offset.strip('%'))/100.0
for i in range(0,len(imgh)):
if location == "horizontal":
axins = inset_axes(ax, cheight, width, loc=3,
bbox_to_anchor=(bmargin+cheight_float*i, offset, 1, 1),
bbox_transform=ax.transAxes,
borderpad=0,
)
cb = plt.colorbar(imgh[i], cax=axins, orientation="horizontal")
elif location == "vertical":
axins = inset_axes(ax, width, cheight, loc=3,
bbox_to_anchor=(1.0+offset, bmargin+cheight_float*i, 1, 1),
bbox_transform=ax.transAxes,
borderpad=0,
)
cb = plt.colorbar(imgh[i], cax=axins)
cb.ax.tick_params(labelsize=ticksize)
# Customize colorbar tick labels
cb.set_ticks(vticks)
if location == "horizontal":
plt.text(bmargin+cheight_float*len(imgh)*0.5, offset+label_offset, label,
horizontalalignment='center',
verticalalignment='center',
fontsize=labelsize,
transform = ax.transAxes)
else:
plt.text(1.0+offset+label_offset, bmargin+cheight_float*len(imgh)*0.5, label,
horizontalalignment='center',
verticalalignment='center',
rotation=90,
fontsize=labelsize,
transform = ax.transAxes)
示例6: plot_reldiag
# 需要导入模块: from mpl_toolkits.axes_grid1 import inset_locator [as 别名]
# 或者: from mpl_toolkits.axes_grid1.inset_locator import inset_axes [as 别名]
def plot_reldiag(reldiag, ax=None):
"""Plot a reliability diagram.
Parameters
----------
reldiag : dict
A reldiag object created by probscores.reldiag_init.
ax : axis handle, optional
Axis handle for the figure. If set to None, the handle is taken from
the current figure (matplotlib.pylab.gca()).
"""
if ax is None:
ax = plt.gca()
# Plot the reliability diagram.
f = 1.0 * reldiag["Y_sum"] / reldiag["num_idx"]
r = 1.0 * reldiag["X_sum"] / reldiag["num_idx"]
mask = np.logical_and(np.isfinite(r), np.isfinite(f))
ax.plot(r[mask], f[mask], "kD-")
ax.plot([0, 1], [0, 1], "k--")
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.grid(True, ls=":")
ax.set_xlabel("Forecast probability")
ax.set_ylabel("Observed relative frequency")
# Plot sharpness diagram into an inset figure.
iax = inset_axes(ax, width="35%", height="20%", loc=4, borderpad=3.5)
bw = reldiag["bin_edges"][2] - reldiag["bin_edges"][1]
iax.bar(
reldiag["bin_edges"][:-1],
reldiag["sample_size"],
width=bw,
align="edge",
color="gray",
edgecolor="black",
)
iax.set_yscale("log", basey=10)
iax.set_xticks(reldiag["bin_edges"])
iax.set_xticklabels(["%.1f" % max(v, 1e-6) for v in reldiag["bin_edges"]])
yt_min = int(max(np.floor(np.log10(min(reldiag["sample_size"][:-1]))), 1))
yt_max = int(np.ceil(np.log10(max(reldiag["sample_size"][:-1]))))
t = [pow(10.0, k) for k in range(yt_min, yt_max)]
iax.set_yticks([int(t_) for t_ in t])
iax.set_xlim(0.0, 1.0)
iax.set_ylim(t[0], 5 * t[-1])
iax.set_ylabel("log10(samples)")
iax.yaxis.tick_right()
iax.yaxis.set_label_position("right")
iax.tick_params(axis="both", which="major", labelsize=6)