Example #1
0
def plotRadialProjection(pattern,
                         parameters,
                         logscale=True,
                         offset=1.e-5,
                         unit="q_nm^-1"):
    """ Perform integration over azimuthal angle and plot as function of radius.

        :param unit:can be "q_nm^-1", "q_A^-1", "2th_deg", "2th_rad", "r_mm".
        :type unit: str

    """

    qs, intensities = azimuthalIntegration(pattern, parameters, unit=unit)

    if logscale:
        plt.semilogy(qs, intensities + offset)
    else:
        plt.plot(qs, intensities)

    if (unit == "q_nm^-1"):
        plt.xlabel("q (1/nm)")
    elif (unit == "q_A^-1"):
        plt.xlabel("q (1/A)")
    elif (unit == "2th_deg"):
        plt.xlabel("2theta (degrees)")
    elif (unit == "2th_rad"):
        plt.xlabel("2theta (radians)")
    elif (unit == "r_mm"):
        plt.xlabel("mm")
    plt.ylabel("Intensity (arb. units)")
    plt.tight_layout()
def plotImage(pattern, logscale=False, offset=1e-1):
    """ Workhorse function to plot an image

    :param logscale: Whether to show the data on logarithmic scale (z axis) (default False).
    :type logscale: bool

    :param offset: Offset to apply if logarithmic scaling is on.
    :type offset: float

    """
    plt.figure()
    # Get limits.
    mn, mx = pattern.min(), pattern.max()

    x_range, y_range = pattern.shape

    if logscale:
        if mn <= 0.0:
            mn += pattern.min() + offset
            pattern = pattern.astype(float) + mn
        plt.imshow(pattern,
                   norm=mpl.colors.LogNorm(vmin=mn, vmax=mx),
                   cmap="viridis")
    else:
        plt.imshow(pattern, norm=Normalize(vmin=mn, vmax=mx), cmap='viridis')

    plt.xlabel(r'$x$ (pixel)')
    plt.ylabel(r'$y$ (pixel)')
    plt.xlim([0, x_range - 1])
    plt.ylim([0, y_range - 1])
    plt.tight_layout()
    plt.colorbar()
Example #3
0
def plotImage(pattern,
              logscale=False,
              offset=1e-1,
              symlog=False,
              *argv,
              **kwargs):
    """ Workhorse function to plot an image

    :param logscale: Whether to show the data on logarithmic scale (z axis) (default False).
    :type logscale: bool

    :param offset: Offset to apply if logarithmic scaling is on.
    :type offset: float

    :param symlog: If logscale is True, to show the data on symlogarithmic scale (z axis) (default False).
    :type symlog: bool

    :return: the handles of figure and axis
    :rtype: figure,axis

    """
    fig, ax = plt.subplots()
    # Get limits.
    mn, mx = pattern.min(), pattern.max()

    x_range, y_range = pattern.shape

    if logscale:
        if mn <= 0.0:
            mn = pattern.min() + offset
            mx = pattern.max() + offset
            pattern = pattern.astype(float) + offset

        # default plot setup
        kwargs['cmap'] = kwargs.pop('cmap', "viridis")
        if symlog:
            kwargs['norm'] = kwargs.pop(
                'norm', mpl.colors.SymLogNorm(0.015, vmin=mn, vmax=mx))
        else:
            kwargs['norm'] = kwargs.pop('norm',
                                        mpl.colors.LogNorm(vmin=mn, vmax=mx))
        axes = kwargs.pop('axes', None)
        plt.imshow(pattern, *argv, **kwargs)
    else:
        kwargs['norm'] = kwargs.pop('norm', Normalize(vmin=mn, vmax=mx))
        kwargs['cmap'] = kwargs.pop('cmap', "viridis")
        plt.imshow(pattern, *argv, **kwargs)

    plt.xlabel(r'$x$ (pixel)')
    plt.ylabel(r'$y$ (pixel)')
    plt.xlim([0, x_range - 1])
    plt.ylim([0, y_range - 1])
    plt.tight_layout()
    plt.colorbar()
    return fig, ax
def plotRadialProjection(pattern, parameters, logscale=True, offset=1.e-5):
    """ Perform integration over azimuthal angle and plot as function of radius. """

    qs, intensities = azimuthalIntegration(pattern, parameters)

    if logscale:
        plt.semilogy(qs, intensities + offset)
    else:
        plt.plot(qs, intensities)

    plt.xlabel("q (1/nm)")
    plt.ylabel("Intensity (arb. units)")
    plt.tight_layout()
Example #5
0
def plotImage(pattern,
              logscale=False,
              offset=None,
              symlog=False,
              *argv,
              **kwargs):
    """ Workhorse function to plot an image

    :param logscale: Whether to show the data on logarithmic scale (z axis) (default False).
    :type logscale: bool

    :param offset: Offset to apply to the pattern.
    :type offset: float

    :param symlog: To show the data on symlogarithmic scale (z axis) (default False).
    :type symlog: bool
    """
    fig, ax = plt.subplots()
    # Get limits.
    mn, mx = pattern.min(), pattern.max()

    x_range, y_range = pattern.shape

    if offset:
        mn = pattern.min() + offset
        mx = pattern.max() + offset
        pattern = pattern.astype(float) + offset

    if (logscale and symlog):
        print('logscale and symlog are both true.\noverrided by logscale')

    # default plot setup
    if (logscale or symlog):
        kwargs['cmap'] = kwargs.pop('cmap', "viridis")
        if logscale:
            kwargs['norm'] = kwargs.pop('norm', mpl.colors.LogNorm())
        elif symlog:
            kwargs['norm'] = kwargs.pop('norm', mpl.colors.SymLogNorm(0.015))
        axes = kwargs.pop('axes', None)
        plt.imshow(pattern, *argv, **kwargs)
    else:
        kwargs['norm'] = kwargs.pop('norm', Normalize(vmin=mn, vmax=mx))
        kwargs['cmap'] = kwargs.pop('cmap', "viridis")
        plt.imshow(pattern, *argv, **kwargs)

    plt.xlabel(r'$x$ (pixel)')
    plt.ylabel(r'$y$ (pixel)')
    plt.xlim([0, x_range - 1])
    plt.ylim([0, y_range - 1])
    plt.tight_layout()
    plt.colorbar()