Python mpl_toolkits.axes_grid1.inset_locator.inset_axes() Examples

The following are 11 code examples of mpl_toolkits.axes_grid1.inset_locator.inset_axes(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mpl_toolkits.axes_grid1.inset_locator , or try the search function .
Example #1
Source File: test_frame.py    From recruit with Apache License 2.0 5 votes vote down vote up
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) 
Example #2
Source File: test_frame.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: test_frame.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: utils.py    From scvelo with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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() 
Example #5
Source File: utils.py    From dynamo-release with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #6
Source File: test_frame.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #7
Source File: test_frame.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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) 
Example #8
Source File: power_spectrums_plots.py    From mmvt with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #9
Source File: test_frame.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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) 
Example #10
Source File: podaactools.py    From podaac_tools_and_services with Apache License 2.0 4 votes vote down vote up
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) 
Example #11
Source File: plots.py    From pysteps with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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)