psynlig.scatter

A module for generating scatter plots of variables.

psynlig.scatter._get_settings_if_empty(settings)[source]

Get settings if None are given.

psynlig.scatter._scatter_1d_flat_class(data, class_data, class_names=None, scaler=None, add_lines=False, add_average=False, cmap_class=None, split_class=False, scatter_settings=None, line_settings=None)[source]

Make a flat plot of several variables.

Here, the points on the x-axis are the variables, while the y-values are points for each data series. The class information is used for coloring.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we are plotting.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings) – A mapping from the class data to labels/names.

  • scalar (callable, optional) – A function that can be used to scale the variables.

  • add_average (boolean, optional) – If True, we will show the averages for each variable.

  • add_lines (boolean, optional) – If True, we will show lines for each “measurement”.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • split_class (boolean, optional) – If True, the plot with class information will be split into one plot for each class.

  • scatter_settings (dict, optional) – Additional settings for the scatter plot.

  • line_settings (dict, optional) – Additional settings for plotting lines.

Returns

psynlig.scatter._scatter_1d_flat_no_class(data, scaler=None, add_average=False, add_lines=False, cmap_lines=None, scatter_settings=None, line_settings=None)[source]

Make a flat plot of several variables.

Here, the points on the x-axis are the variables, while the y-values are points for each data series.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we are plotting.

  • scaler (callable, optional) – A function that can be used to scale the variables.

  • add_average (boolean, optional) – If True, we will show the averages for each variable.

  • add_lines (boolean, optional) – If True, we will show lines for each “measurement”.

  • cmap_lines (string or object like matplotlib.colors.Colormap, optional) – A color map to use for lines.

  • scatter_settings (dict, optional) – Additional settings for the scatter plot.

  • line_settings (dict, optional) – Additional settings for plotting lines.

Returns

psynlig.scatter.create_scatter_legend(axi, color_labels, class_names, show=False, **kwargs)[source]

Generate a legend for a scatter plot with class labels.

Parameters
  • axi (object like matplotlib.axes.Axes) – The axes we will add the legend for.

  • color_labels (dict of objects like numpy.ndarray) – Colors for the different classes.

  • color_names (dict of strings) – Names for the classes.

  • show (boolean, optional) – If True, we will add the legend here.

  • kwargs (dict, optional) – Additional arguments passed to the scatter method. Used here to get a consistent styling.

Returns

  • patches (list of objects like matplotlib.artist.Artist) – The items we will create a legend for.

  • labels (list of strings) – The labels for the legend.

psynlig.scatter.generate_1d_scatter(data, variables, class_data=None, class_names=None, nrows=None, ncols=None, sharex=False, sharey=False, show_legend=True, outliers=False, cmap_class=None, **kwargs)[source]

Generate 1D scatter plots from the given data and variables.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we will plot here.

  • variables (list of strings) – The variables we will generate scatter plots for.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings, optional) – A mapping from the class data to labels/names.

  • nrows (integer, optional) – The number of rows to use in a figure.

  • ncols (integer, optional) – The number of columns to use in a figure.

  • sharex (boolean, optional) – If True, the scatter plots will share the x-axis.

  • sharey (boolean, optional) – If True, the scatter plots will share the y-axis.

  • show_legend (boolean, optional) – If True, we will create a legend here and show it.

  • outliers (boolean, optional) – If True, we will try to mark outliers in the plot.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • kwargs (dict, optional) – Additional arguments used for the plotting.

Returns

psynlig.scatter.generate_2d_scatter(data, variables, class_data=None, class_names=None, nrows=None, ncols=None, sharex=False, sharey=False, show_legend=True, xy_line=False, trendline=False, cmap_class=None, shorten_variables=False, **kwargs)[source]

Generate 2D scatter plots from the given data and variables.

This method will generate 2D scatter plots for all combinations of the given variables.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we will plot here.

  • variables (list of strings) – The variables we will generate scatter plots for.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings, optional) – A mapping from the class data to labels/names.

  • nrows (integer, optional) – The number of rows to use in a figure.

  • ncols (integer, optional) – The number of columns to use in a figure.

  • sharex (boolean, optional) – If True, the scatter plots will share the x-axis.

  • sharey (boolean, optional) – If True, the scatter plots will share the y-axis.

  • show_legend (boolean, optional) – If True, we will create a legend here and show it.

  • xy_line (boolean, optional) – If True, we will add a x=y line to the plot.

  • trendline (boolean, optional) – If True, we will add a trend line to the plot.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • kwargs (dict, optional) – Additional arguments used for the plotting.

Returns

psynlig.scatter.generate_3d_scatter(data, variables, class_data=None, class_names=None, max_plots=5, **kwargs)[source]

Generate 3D scatter plots from the given data and variables.

This method will generate 3D scatter plots for all combinations of the given variables. Note that if the number of plots is large, then no plots will be generated and a warning will be issued. The maximum number of plots to create can be set with the parameter max_plots

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we will plot here.

  • variables (list of strings) – The variables we will generate scatter plots for.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings, optional) – A mapping from the class data to labels/names.

  • max_plots (integer, optional) – The maximum number of plots to create.

  • kwargs (dict, optional) – Additional arguments used for the plotting.

Returns

psynlig.scatter.plot_3d_scatter(data, xvar, yvar, zvar, class_data=None, class_names=None, cmap_class=None, **kwargs)[source]

Make a 3D scatter plot of the given data.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we are plotting.

  • xvar (string) – The column to use as the x-variable.

  • yvar (string) – The column to use as the y-variable.

  • zvar (string) – The column to use as the z-variable

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings, optional) – A mapping from the class data to labels/names.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • kwargs (dict, optional) – Additional arguments used for the plotting.

Returns

psynlig.scatter.plot_scatter(data, xvar, yvar, axi=None, xlabel=None, ylabel=None, class_data=None, class_names=None, highlight=None, cmap_class=None, **kwargs)[source]

Make a 2D scatter plot of the given data.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we are plotting.

  • xvar (string) – The column to use as the x-variable.

  • yvar (string) – The column to use as the y-variable.

  • xlabel (string, optional) – The label to use for the x-axis. If None, we will use xvar.

  • ylabel (string, optional) – The label to use for the y-axis. If None, we will use yvar.

  • axi (object like matplotlib.axes.Axes, optional) – An axis to add the plot to. If this is not provided, a new axis (and figure) will be created here.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings) – A mapping from the class data to labels/names.

  • highlight (list of integers, optional) – This can be used to highlight certain points in the plot.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • kwargs (dict, optional) – Additional settings for the plotting.

Returns

psynlig.scatter.scatter_1d_flat(data, class_data=None, class_names=None, scaler=None, add_average=False, add_lines=False, cmap_lines=None, cmap_class=None, split_class=False, scatter_settings=None, line_settings=None)[source]

Make a flat plot of several variables.

Here, the points on the x-axis are the variables, while the y-values are points for each data series.

Parameters
  • data (object like pandas.core.frame.DataFrame) – The data we are plotting.

  • class_data (object like pandas.core.series.Series, optional) – Class information for the points (if available).

  • class_names (dict of strings) – A mapping from the class data to labels/names.

  • scaler (callable, optional) – A function that can be used to scale the variables.

  • add_average (boolean, optional) – If True, we will show the averages for each variable.

  • add_lines (boolean, optional) – If True, we will show lines for each “measurement”.

  • cmap_lines (string or object like matplotlib.colors.Colormap, optional) – A color map to use for lines.

  • cmap_class (string or object like matplotlib.colors.Colormap, optional) – A color map to use for classes.

  • split_class (boolean, optional) – If True, the plot with class information will be split into one plot for each class.

  • scatter_settings (dict, optional) – Additional settings for the scatter plot.

  • line_settings (dict, optional) – Additional settings for plotting lines.

Returns