plotting
module¶
- pyfasma.plotting.annotate_points(ax: matplotlib.axes.Axes, xys_list=None, ha='center', va='center', xoffset=0, yoffset=0, fontsize=None, **text_kwargs) None ¶
Add annotations/text labels to the specified (x, y) points of a matplotlib.axes.Axes object. Each point annotation is specified as a (x, y, s) tuple inside xys_list, where x, y are the coodrinates of the point and s is the string to be displayed at this point.
This function is based on matplotlib.pyplot.text. See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html
- Parameters:
ax (Axes) – A matplotlib.axes.Axes object in which the annotations will be added.
xys_list (list, optional) – A list containing (x, y, s) tuples where each tuple consists of the x, y coordinates of a point and the string s to be displayed at this point.
ha ({'left', 'center', 'right'}, optional) – The horizontal anchor to which the text is aligned.
va ({'baseline', 'bottom', 'center', 'center_baseline', 'top'}, optional) – The vertical anchor to which the text is aligned.
xoffset (Union[int, float], optional) – Horizontal offset to add to the annotated text.
yoffset (Union[int, float], optional) – Vertical offset to add to the annotated text.
fontsize (float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',) – ‘xx-large’} Set the font size in points. The string values denote sizes relative to the default font size.
**text_kwargs –
Additional keyword arguments are passed to matplotlib.pyplot.text.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html
- pyfasma.plotting.confidence_ellipse(x, y, ax, conf=0.95, facecolor=None, alpha=None, linewidth=None, linestyle=None, edgecolor=None, **kwargs)¶
Create a plot of the covariance confidence ellipse for the points with defined by pairs of x and y values. Each value of y must correspond to a value of x.
- Parameters:
x (array-like, shape (n, )) – x values of the points for which the covariance confidence ellipse is calculated.
y (array-like, shape (n, )) – y values of the points for which the covariance confidence ellipse is calculated.
ax (Axes, optional) – A matplotlib.axes.Axes object in which the plot will be added.
conf (float, optional) – The confidence interval that defines the size of the ellipse. By default the 95% (0.95) confidence interval is used.
facecolor (RGBColorType or 'none') –
Matplotlib-accepted color for the ellipse patch. If ‘none’, no color will be applied to the ellipse patch.
See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
alpha (float, optional) – Set the transparency of the ellipse as a floating-point number in the range 0 (completely transparent line) to 1 (completely opaque line). If None (default), the transparency is set to 1.
linewidth (float, optional) – The width of the ellipse’s outline in points. If None (default), the width is set to 1.5 points.
linestyle (str, optional) –
A Matplotlib-accepted line style for the ellipse’s outline. If None (default), a solid line will be used.
edgecolor (RGBColorType or 'none', optional) –
A Matplotlib-accepted color for the outline of the ellipse. If ‘none’, no color will be applied to the ellipse’s outline.
See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
**kwargs –
Additional keyword arguments are passed to matplotlib.patches.Ellipse.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Ellipse.html
- Returns:
ellipse_patch – The ellipse patch.
- Return type:
matplotlib.patches.Ellipse
- pyfasma.plotting.multiple_lineplots_from_lists(xlist: list, ylist: list, figsize=None, nrows=None, ncols=None, sharex=False, sharey=False, label=None, color=None, alpha=None, linestyle=None, linewidth=None, marker=None, markersize=None, fill=False, fill_alpha=0.25, title=None, title_y=None, xlabel=None, xlabel_bottom=False, ylabel=None, ylabel_left=False, xlim=None, ylim=None, legend=False, legend_loc='best', legend_kwargs={}, **plot_kwargs)¶
Create a plot using lists that contain lists of x and y points to be plotted. Each list in ylist is plotted against a corresponding list in xlist.
This function is based on matplotlib.pyplot.plot. See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
- Parameters:
xlist (list[list]) – List containg lists of x values. Each contained list must correspond to a respective item of the ylist.
ylist (list[list]) – List containg lists of y values.Each contained list must correspond to a respective item of the xlist.
figsize (tuple[float, float], optional) – Set the sjize of the figure as (width, height) in inches. Default (6.4, 4.8).
nrows (int, optional) – Number of subplots rows.
ncols (int, optional) – Number of subplots columns.
sharex (bool or {'none', 'all', 'row', 'col'}) – Controls sharing of properties among the x axis: - True or ‘all’: x-axis will be shared among all subplots. - False or ‘none’: each subplot x-axis will be independent. - ‘row’: each subplot row will share an x-axis. - ‘col’: each subplot column will share an x-axis. When subplots have a shared x-axis along a column, only the x tick labels of the bottom subplot are created. To later turn other subplots’ ticklabels on, use tick_params. When subplots have a shared axis that has units, calling set_units will update the axis with the new units.
sharey (bool or {'none', 'all', 'row', 'col'}) – Controls sharing of properties among the y axis: - True or ‘all’: y-axis will be shared among all subplots. - False or ‘none’: each subplot y-axis will be independent. - ‘row’: each subplot row will share an y-axis. - ‘col’: each subplot column will share an y-axis. When subplots have a shared y-axis along a column, only the y tick labels of the bottom subplot are created. To later turn other subplots’ ticklabels on, use tick_params. When subplots have a shared axis that has units, calling set_units will update the axis with the new units.
label (list[str], optional) – List of strings to be used as labels for the corresponding pairs of xlist and ylist. The labels will be displayed in the legend if legend=True. If None (default), a warning is raised and the legend is returned empty. In this case also using legend=False is recommended.
color (list[RGBColorType], optional) –
List of Matplotlib-accepted colors to be used for the lines drawn for the corresponding pairs of xlist and ylist. If None (default), the default Matplotlib colors will be used.
See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
alpha (list[float], optional) –
List of floating-point numbers that set the transparency of the lines drawn for the corresponding pairs of xlist and ylist. The numbers must be in the range 0 (completely transparent line) to 1 (completely opaque line). If None (default), the transparency for all lines is set to 1.
linestyle (list[str], optional) –
List of Matplotlib-accepted line styles for each of the plotted lines. If None (default), all lines are drawn as solid lines.
linewidth (list[float], optional) – List of floating-point numbers that set the width (in points) of each plotted line. If None (derfault), all lines will have a width of 1.5.
marker (list[str], optional) – List of Matplotlib-accepted markers for each of the plotted lines. If None (default), no markers are drawn. See: https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers
markersize (float, optional) – Set the size (in points) of the markers. If None (default), the default size of 6 will be used.
fill (bool, optional) – If True (default), fill the area below the curve.
fill_alpha (float, optional) – Set the transparency of the filled area. The value of the parameter must be in the range 0 (completely transparent line) to 1 (completely opaque line). Default 0.25.
title (str, optional) – The title of the plot. Default None.
title_y (float, optional) – The y-offset of the title (0.0 bottom, 1.0 top). Default None.
xlabel (str, optional) – The label of the x-axis. Default None.
xlabel_bottom ([TODO]) – [TODO]
ylabel (str, optional) – The label of the y-axis. Default None.
ylabel_left ([TODO]) – [TODO]
xlim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the x-axis.
ylim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the y-axis.
legend (bool, optional) – If True show the plot’s legend.
legend_loc (str or (x, y), optional) –
Set the location of the plot’s legend using parameters accepted by matplotlib.pyplot.legend. The strings ‘upper left’, ‘upper right’, ‘lower left’, ‘lower right’ place the legend at the corresponding corner of the axes. The strings ‘upper center’, ‘lower center’, ‘center left’, ‘center right’ place the legend at the center of the corresponding edge of the axes. The string ‘center’ places the legend at the center of the axes. The string ‘best’ places the legend at the location, among the nine locations defined so far, with the minimum overlap with other drawn artists. This option can be quite slow for plots with large amounts of data; your plotting speed may benefit from providing a specific location. The location can also be a 2-tuple giving the coordinates of the lower-left corner of the legend in axes coordinates.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
legend_kwargs (dict, optional) –
Additional keyword arguments passed as dictionary key: value pairs to matplotlib.axes.Axes.legend.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
**plot_kwargs – Additional keyword arguments are passed to matplotlib.pyplot.plot.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plot.
axes (matplotlib.axes.Axes) – The axes object containing the subplots.
- Raises:
ValueError – If xlist and ylist don’t have the same length.
- pyfasma.plotting.single_lineplot_from_lists(xlist: list, ylist: list, ax=None, figsize=None, label=None, color=None, alpha=None, linestyle=None, linewidth=None, marker=None, markersize=None, fill=False, fill_alpha=0.25, title=None, title_y=None, xlabel=None, ylabel=None, xlim=None, ylim=None, legend=False, legend_loc='best', legend_kwargs={}, **plot_kwargs)¶
Create a plot using lists that contain lists of x and y points to be plotted. Each list in ylist is plotted as a line against a corresponding list in xlist and all lines are plotted in the same plot.
This function is based on matplotlib.pyplot.plot. See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
- Parameters:
xlist (list[list]) – List containg lists of x values. Each contained list must correspond to a respective item of the ylist.
ylist (list[list]) – List containg lists of y values.Each contained list must correspond to a respective item of the xlist.
ax (Axes) – A matplotlib.axes.Axes object in which the plot will be added.
figsize (tuple[float, float], optional) – Set the sjize of the figure as (width, height) in inches. Default (6.4, 4.8).
label (list[str], optional) – List of strings to be used as labels for the corresponding pairs of xlist and ylist. The labels will be displayed in the legend if legend=True. If None (default), a warning is raised and the legend is returned empty. In this case also using legend=False is recommended.
color (list[RGBColorType], optional) –
List of Matplotlib-accepted colors to be used for the lines drawn for the corresponding pairs of xlist and ylist. If None (default), the default Matplotlib colors will be used.
See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
alpha (list[float], optional) –
List of floating-point numbers that set the transparency of the lines drawn for the corresponding pairs of xlist and ylist. The numbers must be in the range 0 (completely transparent line) to 1 (completely opaque line). If None (default), the transparency for all lines is set to 1.
linestyle (list[str], optional) –
List of Matplotlib-accepted line styles for each of the plotted lines. If None (default), all lines are drawn as solid lines.
linewidth (list[float], optional) – List of floating-point numbers that set the width (in points) of each plotted line. If None (derfault), all lines will have a width of 1.5.
marker (list[str], optional) – List of Matplotlib-accepted markers for each of the plotted lines. If None (default), no markers are drawn. See: https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers
markersize (float, optional) – Set the size (in points) of the markers. If None (default), the default size of 6 will be used.
fill (bool, optional) – If True, fill the area below the curve. Default False.
fill_alpha (float, optional) – Set the transparency of the filled area. The value of the parameter must be in the range 0 (completely transparent line) to 1 (completely opaque line). Default 0.25.
title (str, optional) – The title of the plot. Default None.
title_y (float, optional) – The y-offset of the title (0.0 bottom, 1.0 top). Default None.
xlabel (str, optional) – The label of the x-axis. Default None.
ylabel (str, optional) – The label of the y-axis. Default None.
xlim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the x-axis.
ylim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the y-axis.
legend (bool, optional) – If True show the plot’s legend.
legend_loc (str or (x, y), optional) –
Set the location of the plot’s legend using parameters accepted by matplotlib.pyplot.legend. The strings ‘upper left’, ‘upper right’, ‘lower left’, ‘lower right’ place the legend at the corresponding corner of the axes. The strings ‘upper center’, ‘lower center’, ‘center left’, ‘center right’ place the legend at the center of the corresponding edge of the axes. The string ‘center’ places the legend at the center of the axes. The string ‘best’ places the legend at the location, among the nine locations defined so far, with the minimum overlap with other drawn artists. This option can be quite slow for plots with large amounts of data; your plotting speed may benefit from providing a specific location. The location can also be a 2-tuple giving the coordinates of the lower-left corner of the legend in axes coordinates.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
legend_kwargs (dict, optional) –
Additional keyword arguments passed as dictionary key: value pairs to matplotlib.axes.Axes.legend.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
**plot_kwargs – Additional keyword arguments are passed to matplotlib.pyplot.plot.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plot.
ax (matplotlib.axes.Axes) – The axes object containing the plot.
- Raises:
ValueError – If xlist and ylist don’t have the same length.
- pyfasma.plotting.single_lineplot_with_error_from_lists(xlist: list, ylist: list, yerr=None, xerr=None, ax=None, figsize=None, label=None, color=None, alpha=None, linestyle=None, linewidth=None, marker=None, markersize=None, ecolor=None, elinewidth=None, capsize=None, fill=False, fill_alpha=0.25, title=None, title_y=None, xlabel=None, ylabel=None, xlim=None, ylim=None, legend=False, legend_loc='best', legend_kwargs={}, **plot_kwargs)¶
Create a plot using lists that contain lists of x and y points to be plotted along with their error bars. Each list in ylist is plotted as a line against a corresponding list in xlist, while the error bars in the lists of yerr and xerr are drawn on top of the corresponding lists of ylist. All lines along with their error bars are plotted in the same plot.
This function is based on matplotlib.pyplot.plot. See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
- Parameters:
xlist (list[list]) – List containg lists of x values. Each contained list must correspond to a respective item of the ylist.
ylist (list[list]) – List containg lists of y values.Each contained list must correspond to a respective item of the xlist.
yerr (list[list], optional) – List containing lists of vertical error bar values for each list in ylist. Each contained list must correspond to a respective item of the xlist.
xerr (list[list], optional) – List containing lists of horizontal error bar values for each list in ylist. Each contained list must correspond to a respective item of the xlist.
ax (Axes) – A matplotlib.axes.Axes object in which the plot will be added.
figsize (tuple[float, float], optional) – Set the sjize of the figure as (width, height) in inches. Default (6.4, 4.8).
label (list[str], optional) – List of strings to be used as labels for the corresponding pairs of xlist and ylist. The labels will be displayed in the legend if legend=True. If None (default), a warning is raised and the legend is returned empty. In this case also using legend=False is recommended.
color (list[RGBColorType], optional) –
List of Matplotlib-accepted colors to be used for the lines drawn for the corresponding pairs of xlist and ylist. If None (default), the default Matplotlib colors will be used.
See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
alpha (list[float], optional) –
List of floating-point numbers that set the transparency of the lines drawn for the corresponding pairs of xlist and ylist. The numbers must be in the range 0 (completely transparent line) to 1 (completely opaque line). If None (default), the transparency for all lines is set to 1.
linestyle (list[str], optional) –
List of Matplotlib-accepted line styles for each of the plotted lines. If None (default), all lines are drawn as solid lines.
linewidth (list[float], optional) – List of floating-point numbers that set the width (in points) of each plotted line. If None (default), all lines will have a width of 1.5.
marker (list[str], optional) – List of Matplotlib-accepted markers for each of the plotted lines. If None (default), no markers are drawn. See: https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers
markersize (float, optional) – Set the size (in points) of the markers. If None (default), the default size of 6 will be used.
ecolor (list[RGBColorType], optional) – List of Matplotlib-accepted colors to be used for the error bars drawn for the corresponding pairs of xlist and ylist. If None (default), the color that is used to color the line corresponding to the error bar will be used. See: https://matplotlib.org/stable/users/explain/colors/colors.html#colors-def
elinewidth (list[float], optional) – List of floating-point numbers that set the width (in points) of each plotted error bar. If None (default), the linewidth of the current style is used.
capsize (float, optional) – The length of the error bar caps in points.
fill (bool, optional) – If True, fill the area below the curve. Default False.
fill_alpha (float, optional) – Set the transparency of the filled area. The value of the parameter must be in the range 0 (completely transparent line) to 1 (completely opaque line). Default 0.25.
title (str, optional) – The title of the plot. Default None.
title_y (float, optional) – The y-offset of the title (0.0 bottom, 1.0 top). Default None.
xlabel (str, optional) – The label of the x-axis. Default None.
ylabel (str, optional) – The label of the y-axis. Default None.
xlim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the x-axis.
ylim ((float, float), optional) – A tuple of floating-point numbers that sets the lower and upper limits of the y-axis.
legend (bool, optional) – If True show the plot’s legend.
legend_loc (str or (x, y), optional) –
Set the location of the plot’s legend using parameters accepted by matplotlib.pyplot.legend. The strings ‘upper left’, ‘upper right’, ‘lower left’, ‘lower right’ place the legend at the corresponding corner of the axes. The strings ‘upper center’, ‘lower center’, ‘center left’, ‘center right’ place the legend at the center of the corresponding edge of the axes. The string ‘center’ places the legend at the center of the axes. The string ‘best’ places the legend at the location, among the nine locations defined so far, with the minimum overlap with other drawn artists. This option can be quite slow for plots with large amounts of data; your plotting speed may benefit from providing a specific location. The location can also be a 2-tuple giving the coordinates of the lower-left corner of the legend in axes coordinates.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
legend_kwargs (dict, optional) –
Additional keyword arguments passed as dictionary key: value pairs to matplotlib.axes.Axes.legend.
See: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
**plot_kwargs – Additional keyword arguments are passed to matplotlib.pyplot.plot.
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing the plot.
ax (matplotlib.axes.Axes) – The axes object containing the plot.
- Raises:
ValueError – If xlist and ylist don’t have the same length. If xlist and yerr don’t have the same length. If xlist and xerr don’t have the same length.