atompy.create_2d_plot#

atompy.create_2d_plot(*data, plot_kwargs={}, add_colorbar=True, colorbar_kwargs={}, colorbar_label=None, xlabel=None, ylabel=None, title=None, xmin=None, xmax=None, ymin=None, ymax=None, aspect_ratio=1.0, axes_width_inch=2.362204724409449, axes_height_inch=None, make_me_nice=True, make_me_nice_kwargs={})[source]#

Plot 2D data.

Parameters:
data(x, y, z) or (image, extents)

Data to be plotted.

If three arrays are passed, matplotlib.pyplot.pcolormesh() will be used as backend.

If two arrays are passed, matplotlib.pyplot.imshow() will be used as backend.

plot_kwargsdict, optional

Dictionary of keyword arguments passed to either pcolormesh or imshow.

add_colorbarbool, default True

Add a colorbar to the plot. Positioning and properties are controlled with colorbar_kwargs. Uses add_colorbar().

colorbar_kwargsdict, optional

Dictionary of keyword arguments passed to add_colorbar().

xlabel, ylabel, colorbar_labelstr, optional

Optional labels added to the x-axis / y-axis / colorbar.

titlestr, optional

Optional title of the figure.

xmin, xmax, ymin, ymaxfloat, optional

Optionally fix the limits of the x/y axis.

aspect_ratiofloat, default 1.0

Aspect ratio (height/width) of the plot.

Ignored, if both axes_width_inch and axes_height_inch are provided.

axes_width_inchfloat, optional, default 2.36 inch

Physical width of the axes in inches. If not provided, it will be determined automatically.

axes_height_inchfloat, optional

Physical height of the axes in inches. If not provided, it will be determined automatically.

make_me_nicebool, default True

Optimize white space in the figure. See docstring of make_me_nice() for details.

make_me_nice_kwargsdict, optional

Dictionary of keyword arguments passed to make_me_nice().

Returns:
figurematplotlib.figure.Figure
axesmatplotlib.axes.Axes
colorbarmatplotlib.colorbar.Colorbar

Only returned if add_colorbar == True.

Examples

Using matplotlib.pyplot.pcolormesh() backend:

"""
Plot a single 2D-Histogram from a ROOT file.
"""
import atompy as ap
import matplotlib.pyplot as plt

# load 2D histogram from root file to plot it with imshow
x, y, z = ap.load_2d_from_root(
    "example.root", "He_Compton/electrons/momenta/px_vs_py",
    output_format="pcolormesh")

# format figure
plt.rcParams["image.cmap"] = "atom"
plt.rcParams["image.aspect"] = "auto"
plt.rcParams["image.interpolation"] = "none"

fig, ax, cb = ap.create_2d_plot(x, y, z,
                                xlabel=r"$p_x$ (a.u.)",
                                ylabel=r"$p_y$ (a.u.)",
                                colorbar_label="Yield (counts)")

(Source code, png, hires.png, pdf)

../../_images/create_2D_plot_pcolormesh.png

Using matplotlib.pyplot.imshow() backend:

"""
Plot a single 2D-Histogram from a ROOT file.
"""
import atompy as ap
import matplotlib.pyplot as plt

# load 2D histogram from root file to plot it with imshow
image, extents = ap.load_2d_from_root(
    "example.root", "He_Compton/electrons/momenta/px_vs_py",
    output_format="imshow")

# format figure
plt.rcParams["image.cmap"] = "atom"
plt.rcParams["image.aspect"] = "auto"
plt.rcParams["image.interpolation"] = "none"

fig, ax, cb = ap.create_2d_plot(image, extents,
                                xlabel=r"$p_x$ (a.u.)",
                                ylabel=r"$p_y$ (a.u.)",
                                colorbar_label="Yield (counts)")

(Source code, png, hires.png, pdf)

../../_images/create_2D_plot_imshow.png