larray.Array.plot

Array.plot

Plots the data of the array into a graph (window pop-up).

The graph can be tweaked to achieve the desired formatting and can be saved to a .png file.

Parameters:
kind : str
  • ‘line’ : line plot (default)
  • ‘bar’ : vertical bar plot
  • ‘barh’ : horizontal bar plot
  • ‘hist’ : histogram
  • ‘box’ : boxplot
  • ‘kde’ : Kernel Density Estimation plot
  • ‘density’ : same as ‘kde’
  • ‘area’ : area plot
  • ‘pie’ : pie plot
  • ‘scatter’ : scatter plot (if array’s dimensions >= 2)
  • ‘hexbin’ : hexbin plot (if array’s dimensions >= 2)
ax : matplotlib axes object, default None
subplots : boolean, Axis, int, str or tuple, default False

Make several subplots. If True, will make subplots for each combination of labels for all axes except the last. If an Axis, int, str (or tuple of those), it will make subplots for combination of labels of those axes.

sharex : boolean, default True if ax is None else False

In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False if an ax is passed in; Be aware, that passing in both an ax and sharex=True will alter all x axis labels for all axis in a figure!

sharey : boolean, default False

In case subplots=True, share y axis and set some y axis labels to invisible

layout : tuple (optional)

(rows, columns) for the layout of subplots

figsize : a tuple (width, height) in inches
use_index : boolean, default True

Use index as ticks for x axis

title : string

Title to use for the plot

grid : boolean, default None (matlab style default)

Axis grid lines

legend : False/True/’reverse’

Place legend on axis subplots. Defaults to True.

style : list or dict

matplotlib line style per column

logx : boolean, default False

Use log scaling on x axis

logy : boolean, default False

Use log scaling on y axis

loglog : boolean, default False

Use log scaling on both x and y axes

xticks : sequence

Values to use for the xticks

yticks : sequence

Values to use for the yticks

xlim : 2-tuple/list
ylim : 2-tuple/list
rot : int, default None

Rotation for ticks (xticks for vertical, yticks for horizontal plots)

fontsize : int, default None

Font size for xticks and yticks

colormap : str or matplotlib colormap object, default None

Colormap to select colors from. If string, load colormap with that name from matplotlib.

colorbar : boolean, optional

If True, plot colorbar (only relevant for ‘scatter’ and ‘hexbin’ plots)

position : float

Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center)

yerr : array-like

Error bars on y axis

xerr : array-like

Error bars on x axis

stacked : boolean, default False in line and bar plots, and True in area plot.

If True, create stacked plot.

**kwargs : keywords

Options to pass to matplotlib plotting method

Returns:
axes : matplotlib.AxesSubplot or np.array of them

Notes

See Pandas documentation of plot function for more details on this subject

Examples

>>> import matplotlib.pyplot as plt
>>> # let us define an array with some made up data
>>> arr = Array([[5, 20, 5, 10], [6, 16, 8, 11]], 'gender=M,F;year=2018..2021')

Simple line plot

>>> arr.plot()
>>> # show figure (it also resets it after showing it! Do not call it before savefig)
>>> plt.show()

Line plot with grid and a title

>>> arr.plot(grid=True,  title='line plot')
>>> # save figure in a file (see matplotlib.pyplot.savefig documentation for more details)
>>> plt.savefig('my_file.png')

2 bar plots (one for each gender) sharing the same y axis, which makes sub plots easier to compare. By default sub plots are independant of each other and the axes ranges are computed to “fit” just the data for their individual plot.

>>> arr.plot.bar(subplots='gender', sharey=True)
>>> plt.show()

Create a figure containing 2 x 2 graphs

>>> # see matplotlib.pyplot.subplots documentation for more details
>>> fig, ax = plt.subplots(2, 2, figsize=(15, 15))                     # doctest: +SKIP
>>> # line plot with 2 curves (Males and Females) in the top left corner (0, 0)
>>> arr.plot(ax=ax[0, 0], title='line plot')                           # doctest: +SKIP
>>> # bar plot with stacked values in the top right corner (0, 1)
>>> arr.plot.bar(ax=ax[0, 1], stacked=True, title='stacked bar plot')  # doctest: +SKIP
>>> # area plot in the bottom left corner (1, 0)
>>> arr.plot.area(ax=ax[1, 0], title='area plot')                      # doctest: +SKIP
>>> # scatter plot in the bottom right corner (1, 1)
>>> arr.plot.scatter(ax=ax[1, 1], x='M', y='F', title='scatter plot')  # doctest: +SKIP
>>> arr.plot.scatter(ax=ax[1, 1], x='M', y='F', c=arr.year, colormap='viridis',
...                  title='scatter plot')                             # doctest: +SKIP
>>> plt.show()                                                         # doctest: +SKIP