komplot¶
Convenient plotting functions with interactive features.
Alternative high-level interface to selected matplotlib
plotting functions.
Functions
|
Close figure(s). |
|
Configure plotting functions for inline plotting. |
|
Contour plot of a 2D surface. |
|
Contour plot of a 2D surface. |
|
Get the figure event manager attached to a figure. |
|
Display an image. |
|
Display an image. |
|
Plot points or lines in 2D. |
|
Plot points or lines in 2D. |
|
Set matplotlib backend within an ipython shell. |
|
Set matplotlib backend within a Jupyter Notebook shell. |
|
Plot a 2D surface in 3D. |
|
Plot a 2D surface in 3D. |
|
Display a slice of a volume. |
|
Display a slice of a volume. |
Classes
|
Base class for axes-based event managers. |
|
Manager for colorbar events. |
|
State of plot supporting axis zoom and a colorbar. |
|
State of contour plot. |
|
Manager for figure-based events. |
|
Generic plot state. |
|
State of imview plot. |
|
Manager for axes-based events. |
|
State of 2d line/point plot. |
|
State of surface plot. |
|
State of volview plot. |
|
Manager for axes-based events. |
|
Manager for axis zoom events. |
|
State for a plot supporting axis zoom. |
- komplot.contour(z, x=None, y=None, *, xlog=False, ylog=False, levels=5, clabel_inline=True, clabel_format=None, clabel_fontsize=10, cmap=None, vmin=None, vmax=None, alpha=1.0, xlabel=None, ylabel=None, xylabel_fontsize=None, title=None, figsize=None, fignum=None, ax=None)¶
Contour plot of a 2D surface.
Contour plot of a 2D surface together with pseudo-color image representation of the surface. Supports the following features:
If an axes is not specified (via parameter
ax), a new figure and axes are created, andshow()is called after drawing the plot.Interactive features provided by
FigureEventManagerandColorbarEventManagerare supported in addition to the standard matplotlib interactive features.
- Parameters:
z (
ndarray) – Contour data 2d array to plot.xlog (
bool) – Set x-axis to log scale.ylog (
bool) – Set y-axis to log scale.levels (
Union[int,Sequence[float]]) – An int specifying the number of contours to plot, or a sequence specifying the specific contour levels to plot.clabel_inline (
bool) – Value of parameterinlineofclabel().clabel_format (
Optional[str]) – Format string for contour labels.clabel_fontsize (
Optional[int]) – Contour label font size. No contour labels are displayed if set to 0 orNone.cmap (
Union[Colormap,str,None]) – Color map for color mesh drawn under contours. If none specifed, defaults tomatplotlib.cm.YlOrRd.vmin (
Optional[float]) – Set lower bound for the color map (see the corresponding parameter ofimshow()).vmax (
Optional[float]) – Set upper bound for the color map (see the corresponding parameter ofimshow()).alpha (
float) – Underlying image display alpha value.xylabel_fontsize (
Optional[int]) – Axis label font size. The default font size is used if set toNone.figsize (
Optional[Tuple[int,int]]) – Specify dimensions of figure to be creaed as a tuple (width, height) in inches.fignum (
Optional[int]) – Figure number of figure to be created.ax (
Optional[Axes]) – Plot in specified axes instead of creating one.
- Return type:
- Returns:
Contour plot state object.
- class komplot.ContourPlot(*, figure, axes, axesimage, divider, cbar_axes, qcntset)¶
Bases:
ColorbarPlotState of contour plot.
- Parameters:
figure (
Figure) – Plot figure.axes (
Axes) – Plot axes.axesimage (
AxesImage) – TheAxesImageassociated with the colorbar.divider (
AxesDivider) – TheAxesDividerused to create axes for the colorbar.qcntset (
QuadContourSet) – Object returned by the call tocontour().
- komplot.imview(image, *, interpolation='nearest', origin='upper', vmin_quantile=0.0, norm=None, show_cbar=False, cmap=None, title=None, figsize=None, fignum=None, ax=None)¶
Display an image.
Display an image. Pixel values are displayed when the pointer is over valid image data. Supports the following features:
If an axes is not specified (via parameter
ax), a new figure and axes are created, andshow()is called after drawing the plot.Interactive features provided by
FigureEventManagerandImageViewEventManagerare supported in addition to the standard matplotlib interactive features.
- Parameters:
image (
ndarray) – Image to display. It should be two or three dimensional, with the third dimension, if present, representing color and opacity channels, and having size 3 or 4.interpolation (
str) – Specify type of interpolation used to display image (seeinterpolationparameter ofimshow()).origin (
str) – Specify the origin of the image support. Valid values are “upper” and “lower” (seeoriginparameter ofimshow()). The location of the plot x-ticks indicates which of these options was selected.vmin_quantile (
float) – Specify color mapvminandvmaxbased on pixel value quantiles. The default of 0.0 corresponds to settingvminandvmaxto the minimum and maximum pixel value respectively. If it is non-zero,vminandvmaxare set to thevmin_quantilequantile and the 1 -vmin_quantilerespectively.norm (
Optional[Normalize]) – Specify theNormalizeinstance used to scale pixel values for input to the color map. If notNone, it is used to define the color map range instead of thevminandvmaxdetermined byvmin_quantile.show_cbar (
Optional[bool]) – Flag indicating whether to display a colorbar. If set toNone, create an invisible colorbar so that the image occupies the same amount of space in a subplot as one with a visible colorbar.cmap (
Union[Colormap,str,None]) – Color map for image or volume slices. If none specifed, defaults tomatplotlib.cm.Greys_rfor monochrome image.figsize (
Optional[Tuple[int,int]]) – Specify dimensions of figure to be creaed as a tuple (width, height) in inches.fignum (
Optional[int]) – Figure number of figure to be created.ax (
Optional[Axes]) – Plot in specified axes instead of creating one.
- Return type:
- Returns:
Image view state object.
- Raises:
ValueError – If the input array is not of the required shape.
- class komplot.ImageView(*, figure, axes, axesimage, divider, cbar_axes)¶
Bases:
ColorbarPlotState of imview plot.
- Parameters:
figure (
Figure) – Plot figure.axes (
Axes) – Plot axes.axesimage (
AxesImage) – TheAxesImageassociated with the colorbar.divider (
AxesDivider) – TheAxesDividerused to create axes for the colorbar.
- class komplot.ImageViewEventManager(axes, fig_event_man, iview, zoom_scale=2.0, cmap_delta=0.02)¶
Bases:
ColorbarEventManagerManager for axes-based events.
Manage mouse scroll and slider widget events. The following interactive features are supported:
- Mouse wheel scroll
Zoom in or out at current cursor location.
- Mouse wheel scroll in bottom half of colorbar
Increase or decrease colormap
vmin.- Mouse wheel scroll in top half of colorbar
Increase or decrease colormap
vmax.
- Parameters:
axes (
Axes) – Axes to which this manager is attached.fig_event_man (
FigureEventManager) – The figure event manage for the figure to whichaxesbelong.zoom_scale (
float) – Scaling factor for mouse wheel zoom.cmap_delta (
float) – Fraction of colormap range for vmin/vmax shifts.
- komplot.volview(volume, *, slice_axis=0, interpolation='nearest', origin='upper', vmin_quantile=0.0, norm=None, show_cbar=False, cmap=None, title=None, figsize=None, fignum=None, ax=None)¶
Display a slice of a volume.
Display a slice of a volume. Pixel values are displayed when the pointer is over valid image data. Supports the following features:
If an axes is not specified (via parameter
ax), a new figure and axes are created, andshow()is called after drawing the plot.Interactive features provided by
FigureEventManagerandVolumeViewEventManagerare supported in addition to the standard matplotlib interactive features.
- Parameters:
volume (
ndarray) – Volume to display. It should be three or four dimensional. If four dimensional, the final dimension after exclusion of the axis identified byslice_axisrepresents color and opacity channels, should have size 3 or 4.slice_axis (
int) – The axis ofvolume, if any, from which to select volume slices for display.interpolation (
str) – Specify type of interpolation used to display image (seeinterpolationparameter ofimshow()).origin (
str) – Specify the origin of the image support. Valid values are “upper” and “lower” (seeoriginparameter ofimshow()). The location of the plot x-ticks indicates which of these options was selected.vmin_quantile (
float) – Specify color mapvminandvmaxbased on pixel value quantiles. The default of 0.0 corresponds to settingvminandvmaxto the minimum and maximum pixel value respectively. If it is non-zero,vminandvmaxare set to thevmin_quantilequantile and the 1 -vmin_quantilerespectively.norm (
Optional[Normalize]) – Specify theNormalizeinstance used to scale pixel values for input to the color map. If notNone, it is used to define the color map range instead of thevminandvmaxdetermined byvmin_quantile.show_cbar (
Optional[bool]) – Flag indicating whether to display a colorbar. If set toNone, create an invisible colorbar so that the image occupies the same amount of space in a subplot as one with a visible colorbar.cmap (
Union[Colormap,str,None]) – Color map for image or volume slices. If none specifed, defaults tomatplotlib.cm.Greys_rfor monochrome image.figsize (
Optional[Tuple[int,int]]) – Specify dimensions of figure to be creaed as a tuple (width, height) in inches.fignum (
Optional[int]) – Figure number of figure to be created.ax (
Optional[Axes]) – Plot in specified axes instead of creating one.
- Return type:
- Returns:
Volume view state object.
- Raises:
ValueError – If the input array is not of the required shape.
- class komplot.VolumeView(*, figure, axes, axesimage, divider, cbar_axes, volume=None, slice_index=0, slider_axes=None, slider=None)¶
Bases:
ImageViewState of volview plot.
- Parameters:
figure (
Figure) – Plot figure.axes (
Axes) – Plot axes.axesimage (
AxesImage) – TheAxesImageassociated with the colorbar.divider (
AxesDivider) – TheAxesDividerused to create axes for the colorbar.slice_index (
int) – The index of the volume slice.slider_axes (
Optional[Axes]) – The axes of the volume slice index selection slider.slider (
Optional[Slider]) – The volume slice index selection slider widget.
- class komplot.VolumeViewEventManager(axes, fig_event_man, iview, zoom_scale=2.0, cmap_delta=0.02)¶
Bases:
ImageViewEventManagerManager for axes-based events.
Manage mouse scroll and slider widget events. The following interactive features are supported:
- Mouse wheel scroll
Zoom in or out at current cursor location.
- Mouse wheel scroll with shift key depressed
Shift the displayed slice when displaying a volume.
- Click or drag slider widget
Change the displayed slice when displaying a volume.
- Mouse wheel scroll in bottom half of colorbar
Increase or decrease colormap
vmin.- Mouse wheel scroll in top half of colorbar
Increase or decrease colormap
vmax.
- Parameters:
axes (
Axes) – Axes to which this manager is attached.fig_event_man (
FigureEventManager) – The figure event manage for the figure to whichaxesbelong.iview (
VolumeView) – A plot state of typeVolumeView.zoom_scale (
float) – Scaling factor for mouse wheel zoom.cmap_delta (
float) – Fraction of colormap range for vmin/vmax shifts.
- komplot.plot(*args, xlog=False, ylog=False, xlabel=None, ylabel=None, title=None, legend=None, legend_loc=None, figsize=None, fignum=None, ax=None, **kwargs)¶
Plot points or lines in 2D.
Plot points or lines in 2D. Largely replicates the interface of
plot(), with the following execeptionsIf an axes is not specified (via parameter
ax), a new figure and axes are created, andshow()is called after drawing the plot.Interactive features provided by
FigureEventManagerandZoomEventManagerare supported in addition to the standard matplotlib interactive features.
- Parameters:
*args – Plot specification in form
[x], y, [fmt],etc. corresponding to the signature ofplot().xlog (
bool) – Set x axis to log scale ifTrue.ylog (
bool) – Set y axis to log scale ifTrue.legend_loc (
Optional[str]) – Legend location string as supported bylocparameter oflegend().figsize (
Optional[Tuple[int,int]]) – Specify dimensions of figure to be creaed as a tuple (width, height) in inches.fignum (
Optional[int]) – Figure number of figure to be created.ax (
Optional[Axes]) – Plot in specified axes instead of creating one.**kwargs – All keyword arguments of
plot()are supported, such as those specifyingLine2Dproperties (if not specified, the defaults for line width (lw) and marker size (ms) are 1.5 and 6.0 respectively), as well as the following additional keyword arguments. When parametersxlogorylogare specified, additional properties of the log-scale axes may be specified via parametersbase,subs,nonpositive,basex,subsx,nonposx,basey,subsy, andnonposy, supported byloglog().
- Return type:
- Returns:
Line/point plot state object.
- class komplot.LinePlot(*, figure, axes, line2d)¶
Bases:
ZoomablePlotState of 2d line/point plot.
- komplot.surface(z, x=None, y=None, *, elev=None, azim=None, roll=None, alpha=1.0, cmap=None, levels=None, xlabel=None, ylabel=None, zlabel=None, labelpad=8.0, title=None, figsize=None, fignum=None, ax=None)¶
Plot a 2D surface in 3D.
Plot a 2D surface in 3D, together with an optional contour plot in the x-y plane below the surface. Supports the following features:
If an axes is not specified (via parameter
ax), a new figure and axes are created, andshow()is called after drawing the plot.Interactive features provided by
FigureEventManagerare supported in addition to the standard matplotlib interactive features.
- Parameters:
z (
ndarray) – Surface data 2d array to plot.elev (
Optional[float]) – Elevation angle (in degrees); see corresponding parameter ofview_init().azim (
Optional[float]) – Azimuth angle (in degrees); see corresponding parameter ofview_init().roll (
Optional[float]) – Roll angle (in degrees); see corresponding parameter ofview_init().alpha (
float) – Transparency, if specified should be a float between 0.0 and 1.0.cmap (
Union[Colormap,str,None]) – Color map for surface. If none specifed, defaults tomatplotlib.cm.YlOrRd.levels (
Union[int,Sequence[int],None]) – If notNone, plot contours of the surface on the lower end of the z-axis. An int specifies the number of contours to plot, and a sequence specifies the specific contour levels to plot.labelpad (
float) – Label padding.figsize (
Optional[Tuple[int,int]]) – Specify dimensions of figure to be creaed as a tuple (width, height) in inches.fignum (
Optional[int]) – Figure number of figure to be created.ax (
Optional[Axes]) – Plot in specified axes instead of creating one.
- Return type:
- Returns:
Surface plot state object.
- class komplot.SurfacePlot(*, figure, axes, poly3dc, qcntset)¶
Bases:
GenericPlotState of surface plot.
- Parameters:
figure (
Figure) – Plot figure.axes (
Axes) – Plot axes.poly3dc (
Poly3DCollection) – Object returned by the call toplot_surface().qcntset (
Optional[QuadContourSet]) – Object returned by the call tocontour().
- komplot.figure_event_manager(fig, error=True)¶
Get the figure event manager attached to a figure.
- Parameters:
- Raises:
RuntimeError – If error parameter is
Trueand no figure manager attached.- Return type:
- class komplot.FigureEventManager(fig, fig_scale=1.1)¶
Bases:
objectManager for figure-based events.
Manage key-press events, and maintain a record of associated axes and their manager instances. The key-press events provide monitoring of keys used as modifiers for other events (e.g. mouse scroll while shift is depressed) and also support the following keyboard shortcuts:
- q
Close figure. (This is also a standard keyboard shortcut.)
- PageUp/PageDown
Increase or decrease figure size by a scaling factor.
Note that key-press detection is not functional in Jupyter notebooks, including with the interactive ipympl matplotlib backend.
- Parameters:
- static attached_manager(fig, error=False)[source]¶
Get the figure manager attached to a figure.
- Parameters:
- Raises:
RuntimeError – If error parameter is
Trueand no figure manager attached.
- get_axevman_for_axes(ax)[source]¶
Retrieve the axes event manager associated with an axes.
- Parameters:
ax (
Axes) – Axes.- Returns:
The axes event manager associated with an axes.
- register_axevman_for_axes(ax, axem)[source]¶
Register the axes event manager for an axes instance.
- Parameters:
axem (
AxesEventManager) – Axes event manager.ax (
Axes) – Axes.
Define a set of colormap sharing axes.
- class komplot.AxesEventManager(axes, fig_event_man, plot)¶
Bases:
objectBase class for axes-based event managers.
Base class for axes-based event managers.
- Parameters:
axes (
Axes) – Axes to which this manager is attached.fig_event_man (
FigureEventManager) – The figure event manage for the figure to whichaxesbelong.plot (
GenericPlot) – A plot state object.
- class komplot.ZoomEventManager(axes, fig_event_man, zplot, zoom_scale=2.0)¶
Bases:
AxesEventManagerManager for axis zoom events.
Manage axis zoom via mouse wheel scroll.
- Parameters:
axes (
Axes) – Axes to which this manager is attached.fig_event_man (
FigureEventManager) – The figure event manage for the figure to whichaxesbelong.zplot (
ZoomablePlot) – A plot state of typeZoomablePlot.zoom_scale (
float) – Scaling factor for mouse wheel zoom.
- class komplot.ColorbarEventManager(axes, fig_event_man, cbplot, zoom_scale=2.0, cmap_delta=0.02)¶
Bases:
ZoomEventManagerManager for colorbar events.
Manage colormap
vminandvmaxadjustment via mouse scroll in a colorbar. Scrolling in the bottom/left half of the colorbar adjustsvmin, and scrolling in the top/right half of the colorbar adjustsvmax. Axis zoom events on mouse scroll are also supported via theZoomEventManagerbase class.- Parameters:
axes (
Axes) – Axes to which this manager is attached.fig_event_man (
FigureEventManager) – The figure event manage for the figure to whichaxesbelong.cbplot (
ColorbarPlot) – A plot state of typeColorbarPlot.zoom_scale (
float) – Scaling factor for mouse wheel zoom.cmap_delta (
float) – Fraction of colormap range for vmin/vmax shifts.
- cbar_event_rel_pos(event)[source]¶
Determine relative position of event in a colorbar.
- Parameters:
event (Event)
- class komplot.ZoomablePlot(*, figure, axes)¶
Bases:
GenericPlotState for a plot supporting axis zoom.
- class komplot.ColorbarPlot(*, figure, axes, axesimage, divider, cbar_axes)¶
Bases:
ZoomablePlotState of plot supporting axis zoom and a colorbar.
- Parameters:
figure (
Figure) – Plot figure.axes (
Axes) – Plot axes.axesimage (
AxesImage) – TheAxesImageassociated with the colorbar.divider (
AxesDivider) – TheAxesDividerused to create axes for the colorbar.
- komplot.close(fig=None)¶
Close figure(s).
Close figure(s). If a figure object reference or figure number is provided, close the specified figure, otherwise close all figures.
- komplot.config_notebook_plotting(backend=None)¶
Configure plotting functions for inline plotting.
Configure plotting functions for inline plotting within a Jupyter notebook shell. This function has no effect when not within a notebook shell, and may therefore be used within a normal Python script. If environment variable
MATPLOTLIB_IPYNB_BACKENDis set, the matplotlib backend is explicitly set to the specified value.- Parameters:
backend (
Optional[str]) – Name of backend to be passed toset_notebook_plot_backend().
- komplot.set_ipython_plot_backend(backend='qt')¶
Set matplotlib backend within an ipython shell.
Set matplotlib backend within an ipython shell. This function has the same effect as the line magic
%matplotlib [backend]but is called as a function and includes a check to determine whether the code is running in an ipython shell, so that it can safely be used within a normal python script since it has no effect when not running in an ipython shell.- Parameters:
backend (
str) – Name of backend to be passed to the%matplotlibline magic command.
- komplot.set_notebook_plot_backend(backend=None)¶
Set matplotlib backend within a Jupyter Notebook shell.
Set matplotlib backend within a Jupyter Notebook shell. This function has the same effect as the line magic
%matplotlib [backend]but is called as a function and includes a check to determine whether the code is running in a notebook shell, so that it can safely be used within a normal python script since it has no effect when not running in a notebook shell.
- komplot.contour_(*args, **kwargs)¶
Contour plot of a 2D surface.
This version of
contour()discards the return value, for use in Jupyter notebooks where the return value is not needed, and which would clutter the following output cell.
- komplot.imview_(*args, **kwargs)¶
Display an image.
This version of
imview()discards the return value, for use in Jupyter notebooks where the return value is not needed, and which would clutter the following output cell.
- komplot.plot_(*args, **kwargs)¶
Plot points or lines in 2D.
This version of
plot()discards the return value, for use in Jupyter notebooks where the return value is not needed, and which would clutter the following output cell.