kwplot.mpl_multiplot module¶
DEPRECATED: Use seaborn instead
- kwplot.mpl_multiplot.multi_plot(xdata=None, ydata=None, xydata=None, **kwargs)[source]¶
plots multiple lines, bars, etc…
One function call that concisely describes the all of the most commonly used parameters needed when plotting a bar / line char. This is especially useful when multiple plots are needed in the same domain.
- Parameters
xdata (List[ndarray] | Dict[str, ndarray] | ndarray) – x-coordinate data common to all y-coordinate values or xdata for each line/bar in ydata. Mutually exclusive with xydata.
ydata (List[ndarray] | Dict[str, ndarray] | ndarray) – y-coordinate values for each line/bar to plot. Can also be just a single ndarray of scalar values. Mutually exclusive with xydata.
xydata (Dict[str, Tuple[ndarray, ndarray]]) – mapping from labels to a tuple of xdata and ydata for a each line.
**kwargs –
- fnum (int):
figure number to draw on
- pnum (Tuple[int, int, int]):
plot number to draw on within the figure, e.g. (1, 1, 1)
- label (List|Dict):
if you specified ydata as a List[ndarray] this is the label for each line in that list. Note this is unnecessary if you specify input as a dictionary mapping labels to lines.
- color (str|List|Dict):
either a special color code, a single color, or a color for each item in ydata. In the later case, this should be specified as either a list or a dict depending on how ydata was specified.
- marker (str|List|Dict):
type of matplotlib marker to use at every data point. Can be specified for all lines jointly or for each line independently.
- transpose (bool, default=False):
swaps x and y data.
- kind (str, default=’plot’):
The kind of plot. Can either be ‘plot’ or ‘bar’. We parse these other kwargs if:
- if kind=’plot’:
spread
- if kind=’bar’:
stacked, width
- Misc:
use_legend (bool): … legend_loc (str):
one of ‘best’, ‘upper right’, ‘upper left’, ‘lower left’, ‘lower right’, ‘right’, ‘center left’, ‘center right’, ‘lower center’, or ‘upper center’.
- Layout:
xlabel (str): label for x-axis ylabel (str): label for y-axis title (str): title for the axes figtitle (str): title for the figure
xscale (str): can be one of [linear, log, logit, symlog] yscale (str): can be one of [linear, log, logit, symlog]
xlim (Tuple[float, float]): low and high x-limit of axes ylim (Tuple[float, float]): low and high y-limit of axes xmin (float): low x-limit of axes, mutex with xlim xmax (float): high x-limit of axes, mutex with xlim ymin (float): low y-limit of axes, mutex with ylim ymax (float): high y-limit of axes, mutex with ylim
titlesize (float): … legendsize (float): … labelsize (float): …
- Grid:
gridlinewidth (float): … gridlinestyle (str): …
- Ticks:
num_xticks (int): number of x ticks num_yticks (int): number of y ticks tickwidth (float): … ticklength (float): … ticksize (float): … xticklabels (list): list of x-tick labels, overrides num_xticks yticklabels (list): list of y-tick labels, overrides num_yticks xtick_rotation (float): xtick rotation in degrees ytick_rotation (float): ytick rotation in degrees
- Data:
- spread (List | Dict): Plots a spread around plot lines usually
indicating standard deviation
markersize (float|List|Dict): marker size for all or each plot markeredgewidth (float|List|Dict): marker edge width for all or each plot linewidth (float|List|Dict): line width for all or each plot linestyle (str|List|Dict): line style for all or each plot
Note
any plot_kw key can be a scalar (corresponding to all ydatas), a list if ydata was specified as a list, or a dict if ydata was specified as a dict.
- plot_kw_keys = [‘label’, ‘color’, ‘marker’, ‘markersize’,
‘markeredgewidth’, ‘linewidth’, ‘linestyle’]
Note
In general this should be deprecated in favor of using seaborn
- Returns
ax : the axes that was drawn on
- Return type
matplotlib.axes.Axes
References
matplotlib.org/examples/api/barchart_demo.html
Example
>>> import kwplot >>> kwplot.autompl() >>> # The new way to use multi_plot is to pass ydata as a dict of lists >>> ydata = { >>> 'spamΣ': [1, 1, 2, 3, 5, 8, 13], >>> 'eggs': [3, 3, 3, 3, 3, np.nan, np.nan], >>> 'jamµ': [5, 3, np.nan, 1, 2, np.nan, np.nan], >>> 'pram': [4, 2, np.nan, 0, 0, np.nan, 1], >>> } >>> ax = kwplot.multi_plot(ydata=ydata, title='ΣΣΣµµµ', >>> xlabel='\nfdsΣΣΣµµµ', linestyle='--') >>> kwplot.show_if_requested()
Example
>>> # Old way to use multi_plot is a list of lists >>> import kwplot >>> kwplot.autompl() >>> xdata = [1, 2, 3, 4, 5] >>> ydata_list = [[1, 2, 3, 4, 5], [3, 3, 3, 3, 3], [5, 4, np.nan, 2, 1], [4, 3, np.nan, 1, 0]] >>> kwargs = {'label': ['spamΣ', 'eggs', 'jamµ', 'pram'], 'linestyle': '-'} >>> #ax = multi_plot(xdata, ydata_list, title='$\phi_1(\\vec{x})$', xlabel='\nfds', **kwargs) >>> ax = multi_plot(xdata, ydata_list, title='ΣΣΣµµµ', xlabel='\nfdsΣΣΣµµµ', **kwargs) >>> kwplot.show_if_requested()
Example
>>> # Simple way to use multi_plot is to pass xdata and ydata exactly >>> # like you would use plt.plot >>> import kwplot >>> kwplot.autompl() >>> ax = multi_plot([1, 2, 3], [4, 5, 6], fnum=4, label='foo') >>> kwplot.show_if_requested()
Example
>>> import kwplot >>> kwplot.autompl() >>> xydata = {'a': ([0, 1, 2], [0, 1, 2]), 'b': ([0, 2, 4], [2, 1, 0])} >>> ax = kwplot.multi_plot(xydata=xydata, fnum=4) >>> kwplot.show_if_requested()
Example
>>> import kwplot >>> kwplot.autompl() >>> ydata = {'a': [0, 1, 2], 'b': [1, 2, 1], 'c': [4, 4, 4, 3, 2]} >>> kwargs = { >>> 'spread': {'a': [.2, .3, .1], 'b': .2}, >>> 'xlim': (-1, 5), >>> 'xticklabels': ['foo', 'bar'], >>> 'xtick_rotation': 90, >>> } >>> ax = kwplot.multi_plot(ydata=ydata, fnum=4, **kwargs) >>> kwplot.show_if_requested()