larray.Array.plot

property 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
kindstr
  • ‘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)

axmatplotlib axes object, default None
subplotsboolean, default False

Make separate subplots for each column

sharexboolean, 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!

shareyboolean, default False

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

layouttuple (optional)

(rows, columns) for the layout of subplots

figsizea tuple (width, height) in inches
use_indexboolean, default True

Use index as ticks for x axis

titlestring

Title to use for the plot

gridboolean, default None (matlab style default)

Axis grid lines

legendFalse/True/’reverse’

Place legend on axis subplots

stylelist or dict

matplotlib line style per column

logxboolean, default False

Use log scaling on x axis

logyboolean, default False

Use log scaling on y axis

loglogboolean, default False

Use log scaling on both x and y axes

xtickssequence

Values to use for the xticks

ytickssequence

Values to use for the yticks

xlim2-tuple/list
ylim2-tuple/list
rotint, default None

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

fontsizeint, default None

Font size for xticks and yticks

colormapstr or matplotlib colormap object, default None

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

colorbarboolean, optional

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

positionfloat

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

layouttuple (optional)

(rows, columns) for the layout of the plot

yerrarray-like

Error bars on y axis

xerrarray-like

Error bars on x axis

stackedboolean, default False in line and bar plots, and True in area plot.

If True, create stacked plot.

**kwargskeywords

Options to pass to matplotlib plotting method

Returns
axesmatplotlib.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 
>>> a = ndtest('sex=M,F;age=0..20')

Simple line plot

>>> a.plot() 
>>> # shows figure (reset the current figure after showing it! Do not call it before savefig)
>>> plt.show() 

Line plot with grid, title and both axes in logscale

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

2 bar plots sharing the same x axis (one for males and one for females)

>>> a.plot.bar(subplots=True, sharex=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)) 
>>> # 2 curves : Males and Females
>>> a.plot(ax=ax[0, 0], title='line plot') 
>>> # bar plot with stacked values
>>> a.plot.bar(ax=ax[0, 1], stacked=True, title='stacked bar plot') 
>>> # same as previously but with colored areas instead of bars
>>> a.plot.area(ax=ax[1, 0], title='area plot') 
>>> # scatter plot
>>> a.plot.scatter(ax=ax[1, 1], x='M', y='F', title='scatter plot') 
>>> plt.show()