Matplotlib utilities¶
This module contains a number of helper functions for matplotlib.
For details about various arguments, such as allowed key word arguments and how they will be interpreted, please consult the appropriate parts of the matplotlib documentation:
- Lines: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D
- Patches: https://matplotlib.org/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch
- Scatter plots: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter
- Text: https://matplotlib.org/api/text_api.html#matplotlib.text.Text
Adjusting axis properties¶
Fonts
set_legend_title_fontsize (ax, fontsize, str]) |
Set the font size of the title of the legend. |
set_legend_fontsize (ax, fontsize, str]) |
Set the font size of the items of the legend. |
set_title_fontsize (ax, fontsize, str]) |
Set the font size of the title of the axis. |
set_label_fontsize (ax, fontsize, str], axis) |
Set the font size of the labels of the axis. |
set_ticklabels_fontsize (ax, fontsize, str], …) |
Set the font size of the tick labels |
set_ticklabel_rotation (ax, rotation, str], …) |
Set the rotation of the tick labels |
Axes
center_splines (ax) |
Places the splines of ax in the center of the plot. |
hide_first_y_tick_label (ax) |
Hide the first tick label on the y-axis |
hide_tick_labels_by_text (ax, to_remove_x, …) |
Hide tick labels which match the given values. |
hide_tick_labels_by_index (ax, keep_x, …) |
Hide the tick labels on both axes. |
Creating standard plots¶
plot_simple_bar_chart (bars, ax, labels, …) |
Plot a simple bar chart based on the values in bars |
plot_simple_scatter (x, y, ax, equal_aspect, …) |
Plot a simple scatter plot of x vs. |
plot_stacked_bar_graph (ax, data[, colors, …]) |
Create a stacked bar plot with the given characteristics. |
plot_sorted_values (values, ymin, ymax, ax, …) |
Sort values and plot them |
Plotting standard machine learning and statistical results¶
plot_binary_prediction_scores (y_scores, …) |
Plot separate lines for the scores of the positives and negatives |
plot_confusion_matrix (confusion_matrix, ax, …) |
Plot the given confusion matrix |
plot_roc_curve (tpr, fpr, auc, show_points, …) |
Plot the ROC curve for the given fpr and tpr values |
plot_trend_line (x, intercept, slope, power, …) |
Draw the trend line implied by the given coefficients. |
plot_venn_diagram (sets, Sequence], ax, …) |
Wrap the matplotlib_venn package. |
Other helpers¶
add_fontsizes_to_args (args, …) |
Add reasonable default fontsize values to args |
draw_rectangle (ax, base_x, base_y, width, …) |
Draw a rectangle at the given x and y coordinates. |
get_diff_counts (data_np) |
This function extracts the differential counts necessary for visualization with stacked_bar_graph. |
Definitions¶
This module contains a number of helper functions for matplotlib.
For details about various arguments, such as allowed key word arguments and how they will be interpreted, please consult the appropriate parts of the matplotlib documentation:
- Lines: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D
- Patches: https://matplotlib.org/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch
- Scatter plots: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter
- Text: https://matplotlib.org/api/text_api.html#matplotlib.text.Text
-
pyllars.mpl_utils.
VALID_AXIS_VALUES
= {'both', 'x', 'y'}¶ Valid axis values
-
pyllars.mpl_utils.
VALID_WHICH_VALUES
= {'both', 'major', 'minor'}¶ Valid which values
-
pyllars.mpl_utils.
X_AXIS_VALUES
= {'both', 'x'}¶ axis choices which affect the X axis
-
pyllars.mpl_utils.
Y_AXIS_VALUES
= {'both', 'y'}¶ axis choices which affect the Y axis
-
pyllars.mpl_utils.
_get_fig_ax
(ax: Optional[matplotlib.axes._axes.Axes])[source]¶ Grab a figure and axis from ax, or create a new one
-
pyllars.mpl_utils.
add_fontsizes_to_args
(args: argparse.Namespace, legend_title_fontsize: int = 12, legend_fontsize: int = 10, title_fontsize: int = 20, label_fontsize: int = 15, ticklabels_fontsize: int = 10)[source]¶ Add reasonable default fontsize values to args
-
pyllars.mpl_utils.
center_splines
(ax: matplotlib.axes._axes.Axes) → None[source]¶ Places the splines of ax in the center of the plot.
This is useful for things like scatter plots where (0,0) should be in the center of the plot.
Parameters: ax (matplotlib.axes.Axes) – The axis Returns: Return type: None, but the splines are updated
-
pyllars.mpl_utils.
draw_rectangle
(ax: matplotlib.axes._axes.Axes, base_x: float, base_y: float, width: float, height: float, center_x: bool = False, center_y: bool = False, **kwargs) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Draw a rectangle at the given x and y coordinates.
Optionally, these can be adjusted such that they are the respective centers rather than edge values.
Parameters: - ax (matplotlib.axes.Axes) – The axis on which the rectangle will be drawn
- base_{x,y} (float) – The base x and y coordinates
- {width,height} (float) – The width (change in x) and height (change in y) of the rectangle
- center_{x,y} (bool) – Whether to adjust the x and y coordinates such that they become the center rather than lower left. In particular, if center_x is True, then base_x will be shifted left by width/2; likewise, if center_y is True, then base_y will be shifted down by height/2.
- **kwargs (key=value pairs) – Additional keywords are passed to the patches.Rectangle constructor. Please see the matplotlib documentation for more details: https://matplotlib.org/api/_as_gen/matplotlib.patches.Rectangle.html
Returns: - fig (matplotlib.figure.Figure) – The figure on which the rectangle was drawn
- ax (matplotlib.axes.Axes) – The axis on which the rectangle was drawn
-
pyllars.mpl_utils.
get_diff_counts
(data_np)[source]¶ This function extracts the differential counts necessary for visualization with stacked_bar_graph. It assumes the counts for each bar are given as a separate row in the numpy 2-d array. Within the rows, the counts are ordered in ascending order. That is, the first column contains the smallest count, the second column contains the next-smallest count, etc.
For example, if the columns represnt some sort of filtering approach, then the last column would contain the unfiltered count, the next-to-last column would give the count after the first round of filtering, etc.
-
pyllars.mpl_utils.
hide_first_y_tick_label
(ax: matplotlib.axes._axes.Axes) → None[source]¶ Hide the first tick label on the y-axis
Parameters: ax (matplotlib.axes.Axes) – The axis Returns: Return type: None, but the tick label is hidden
-
pyllars.mpl_utils.
hide_tick_labels
(ax: matplotlib.axes._axes.Axes, axis: str = 'both') → None[source]¶ Hide the tick labels on the specified axes.
Optionally, some can be preserved.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- axis (str in {both, x, y}) – Axis of the tick labels to hide
Returns: Return type: None, but the tick labels of the axis are removed, as specified
-
pyllars.mpl_utils.
hide_tick_labels_by_index
(ax: matplotlib.axes._axes.Axes, keep_x: Collection = {}, keep_y: Collection = {}, axis: str = 'both') → None[source]¶ Hide the tick labels on both axes.
Optionally, some can be preserved.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- keep_{x,y} (typing.Collection[int]) – The indices of any x-axis ticks to keep. The numbers are passed directly as indices to the “ticks” arrays.
- axis (str in {both, x, y}) – Axis of the tick labels to hide
Returns: Return type: None, but the tick labels of the axis are removed, as specified
-
pyllars.mpl_utils.
hide_tick_labels_by_text
(ax: matplotlib.axes._axes.Axes, to_remove_x: Collection = {}, to_remove_y: Collection = {}) → None[source]¶ Hide tick labels which match the given values.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- to_remove_{x,y} (typing.Collection[str]) – The values to remove
Returns: Return type: None, but the specified tick labels are hidden
-
pyllars.mpl_utils.
plot_binary_prediction_scores
(y_scores: Sequence[float], y_true: Sequence[int], positive_label: int = 1, positive_line_color='g', negative_line_color='r', line_kwargs: Mapping = {}, positive_line_kwargs: Mapping = {}, negative_line_kwargs: Mapping = {}, title: Optional[str] = None, ylabel: Optional[str] = 'Score', xlabel: Optional[str] = 'Instance', title_font_size: int = 20, label_font_size: int = 15, ticklabels_font_size: int = 15, ax: Optional[matplotlib.axes._axes.Axes] = None) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Plot separate lines for the scores of the positives and negatives
Parameters: - y_scores (typing.Sequence[float]) – The predicted scores of the positive class. For example, this may be found using something like: y_scores = y_proba_pred[:,1] for probabilistic predictions from most sklearn classifiers.
- y_true (typing.Sequence[int]) – The ground truth labels
- positive_label (int) – The value for the “positive” class
- {positive,negative}_line_color (color) –
Values to use for the color of the respective lines. These can be anything which matplotlib.plot can interpret.
These values have precedent over the other kwargs parameters.
- line_kwargs (typing.Mapping) – Other keyword arguments passed through to plot for both lines.
- {positive,negative}_line_kwargs (typing.Mapping) –
Other keyword arguments pass through to plot for only the respective line.
These values have precedent over line_kwargs.
- title (typing.Optional[str]) – If given, the title of the axis is set to this value
- {y,x}label (typing.Optional[str]) – Text for the respective labels
- {title,label,ticklabels}_font_size (int) – The font sizes for the respective elements.
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
Returns: - fig (matplotlib.figure.Figure) – The figure on which the scores lines were plotted
- ax (matplotlib.axes.Axes) – The axis on which the score lines were plotted
-
pyllars.mpl_utils.
plot_confusion_matrix
(confusion_matrix: numpy.ndarray, ax: Optional[matplotlib.axes._axes.Axes] = None, show_cell_labels: bool = True, show_colorbar: bool = True, title: Optional[str] = 'Confusion matrix', cmap: matplotlib.colors.Colormap = <matplotlib.colors.LinearSegmentedColormap object>, true_tick_labels: Optional[Sequence[str]] = None, predicted_tick_labels: Optional[Sequence[str]] = None, ylabel: Optional[str] = 'True labels', xlabel: Optional[str] = 'Predicted labels', title_font_size: int = 20, label_font_size: int = 15, true_tick_rotation: Union[str, int, None] = None, predicted_tick_rotation: Union[str, int, None] = None, out: Optional[str] = None) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Plot the given confusion matrix
Parameters: - confusion_matrix (numpy.ndarray) – A 2-d array, presumably from
sklearn.metrics.confusion_matrix()
or something similar. The rows (Y axis) are the “true” classes while the columns (X axis) are the “predicted” classes. - ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- show_cell_labels (bool) – Whether to show the values within each cell
- show_colorbar (bool) – Whether to show a color bar
- title (typing.Optional[str]) – If given, the title of the axis is set to this value
- cmap (matplotlib.colors.Colormap) – A colormap to determine the cell colors
- {true,predicted}_tick_labels (typing.Optional[typing.Sequence[str]]) – Text for the Y (true) and X (predicted) axis, respectively
- {y,x}label (typing.Optional[str]) – Text for the respective labels
- {title,label}_font_size (int) – The font sizes for the respective elements. The class labels (on the tick marks) use the label_font_size.
- {true,predicted}_tick_rotation (typing.Optional[IntOrString]) – The rotation arguments for the respective tick labels. Please see the matplotlib text documentation (https://matplotlib.org/api/text_api.html#matplotlib.text.Text) for more details.
- out (typing.Optional[str]) – If given, the plot will be saved to this file.
Returns: - fig (matplotlib.figure.Figure) – The figure on which the confusion matrix was plotted
- ax (matplotlib.axes.Axes) – The axis on which the confusion matrix was plotted
- confusion_matrix (numpy.ndarray) – A 2-d array, presumably from
-
pyllars.mpl_utils.
plot_mean_roc_curve
(tprs: Sequence[Sequence[float]], fprs: Sequence[Sequence[float]], aucs: Optional[float] = None, label_note: Optional[str] = None, line_style: Mapping = {'alpha': 0.8, 'c': 'b', 'lw': 2}, fill_style: Mapping = {'alpha': 0.2, 'color': 'grey'}, show_xy_line: bool = True, xy_line_kwargs: Mapping = {'color': 'r', 'ls': '--', 'lw': 2}, ax: Optional[matplotlib.axes._axes.Axes] = None, title: Optional[str] = None, xlabel: Optional[str] = 'False positive rate', ylabel: Optional[str] = 'True positive rate', title_font_size: int = 25, label_font_size: int = 20, ticklabels_font_size: int = 20) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Plot the mean plus/minus the standard deviation of the given ROC curves
Parameters: - tprs (typing.Sequence[typing.Sequence[float]]) – The true positive rate at each threshold
- fprs (typing.Sequence[typing.Sequence[float]]) – The false positive rate at each threshold
- aucs (typing.Optional[float]) – The calculated area under the ROC curve
- label_note (typing.Optional[str]) – A prefix for the label in the legend for this line.
- {line,fill}_style (typing.Mapping) – Keyword arguments for plotting the line and fill_between, respectively. Please see the mpl docs for more details.
- show_xy_line (bool) – Whether to draw the y=x line
- xy_line_kwargs (typing.Mapping) – Keyword arguments for plotting the x=y line.
- title (typing.Optional[str]) – If given, the title of the axis is set to this value
- {x,y}label (typing.Optional[str]) – Text for the respective labels
- {title,label,ticklabels}_font_size (int) – The font sizes for the respective elements
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
Returns: - fig (matplotlib.figure.Figure) – The figure on which the ROC curves were plotted
- ax (matplotlib.axes.Axes) – The axis on which the ROC curves were plotted
-
pyllars.mpl_utils.
plot_roc_curve
(tpr: Sequence[Sequence[float]], fpr: Sequence[Sequence[float]], auc: Optional[float] = None, show_points: bool = True, ax: Optional[matplotlib.axes._axes.Axes] = None, method_names: Optional[Sequence[str]] = None, out: Optional[str] = None, line_colors: Optional[Sequence] = None, point_colors: Optional[Sequence] = None, alphas: Optional[Sequence[float]] = None, line_kwargs: Optional[Mapping] = None, point_kwargs: Optional[Mapping] = None, title: Optional[str] = 'Receiver operating characteristic curves', xlabel: Optional[str] = 'False positive rate', ylabel: Optional[str] = 'True positive rate', title_font_size: int = 20, label_font_size: int = 15, ticklabels_font_size: int = 15) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Plot the ROC curve for the given fpr and tpr values
Currently, this function plots multiple ROC curves.
Optionally, add a note of the auc.
Parameters: - tpr (typing.Sequence[typing.Sequence[float]]) – The true positive rate at each threshold
- fpr (typing.Sequence[typing.Sequence[float]]) – The false positive rate at each threshold
- auc (typing.Optional[float]) – The calculated area under the ROC curve
- show_points (bool) – Whether to plot points at each threshold
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- method_names (typing.Optional[typing.Sequence[str]]) – The name of each method
- out (typing.Optional[str]) – If given, the plot will be saved to this file.
- line_colors (typing.Optional[typing.Sequence[color]]) – The color of each ROC line
- point_colors (typing.Optional[typing.Sequence[color]]) – The color of the points on each each ROC line
- alphas (typing.Optional[typing.Sequence[float]]) – An alpha value for each method
- {line,point}_kwargs (typing.Optional[typing.Mapping]) – Additional keyword arguments for the respective elements
- title (typing.Optional[str]) – If given, the title of the axis is set to this value
- {x,y}label (typing.Optional[str]) – Text for the respective labels
- {title,label,ticklabels}_font_size (int) – The font sizes for the respective elements
Returns: - fig (matplotlib.figure.Figure) – The figure on which the ROC curves were plotted
- ax (matplotlib.axes.Axes) – The axis on which the ROC curves were plotted
-
pyllars.mpl_utils.
plot_simple_bar_chart
(bars: Sequence[Sequence[float]], ax: Optional[matplotlib.axes._axes.Axes] = None, labels: Optional[Sequence[str]] = None, colors: Union[matplotlib.colors.Colormap, Sequence, int] = <matplotlib.colors.LinearSegmentedColormap object>, xticklabels: Union[str, Sequence[str], None] = 'default', xticklabels_rotation: Union[int, str] = 'vertical', xlabel: Optional[str] = None, ylabel: Optional[str] = None, spacing: float = 0, ymin: Optional[float] = None, ymax: Optional[float] = None, use_log_scale: bool = False, hide_first_ytick: bool = True, show_legend: bool = False, title: Optional[str] = None, tick_fontsize: int = 12, label_fontsize: int = 12, legend_fontsize: int = 12, title_fontsize: int = 12, tick_offset: float = 0.5)[source]¶ Plot a simple bar chart based on the values in bars
Parameters: - bars (typing.Sequence[typing.Sequence[float]]) –
The heights of each bar. The “outer” sequence corresponds to each clustered group of bars, while the “inner” sequence gives the heights of each bar within the group.
As a data science example, the “outer” groups may correspond to different datasets, while the “inner” group corresponds to different methods.
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- labels (typing.Optional[typing.Sequence[str]]) – The label for each “outer” group in bars
- colors (BarChartColorOptions) –
The colors of the bars for each “inner” group. The options and their interpretations are:
- color map : the color of each bar will be taken as equi-distant colors sampled from the map. For example, if there are three bars in thei nner group, then the colors will be: colors(0.0), colors(0.5), and colors(1.0).
- sequence of colors : the color of each bar will be taken from the respective position in the sequence.
- scalar (int or str) : all bars will use this color
- xticklabels (typing.Optional[typing.Union[str,typing.Sequence[str]]]) –
The tick labels for the “outer” groups. The options and their interpretations are:
- None : no tick labels will be shown
- ”default” : the tick labels will be the numeric tick positions
- sequence of strings : the tick labels will be the respective strings
- xticklabels_rotation (typing.Union[str,int]) – The rotation for the xticklabels. If a string is given, it should be something which matplotlib can interpret as a rotation.
- {x,y}label (typing.Optional[str]) – Labels for the respective axes
- spacing (float) – The distance on the x axis between the “outer” groups.
- y{min,max} (typing.Optional[float]) – The min and max for the y axis. If not given, the default min is 0 (or 1 if a logarithmic scale is used, see option below), and the default max is 2 times the height of the highest bar in any group.
- use_log_scale (bool) – Whether to use a normal or logarithmic scale for the y axis
- hide_first_ytick (bool) – Whether to hide the first tick mark and label on the y axis. Typically, the first tick mark is either 0 or 1 (depending on the scale of the y axis). This can be distracting to see, so the default is to hide it.
- show_legend (bool) – Whether to show the legend
- title (typing.Optional[str]) – A title for the axis
- {tick,label,legend,title}_fontsize (int) – The font size for the respective elements
- tick_offset (float) – The offset of the tick mark and label for the outer groups on the x axis
Returns: - fig (matplotlib.figure.Figure) – The figure on which the bars were plotted
- ax (matplotlib.axes.Axes) – The axis on which the bars were plotted
- bars (typing.Sequence[typing.Sequence[float]]) –
-
pyllars.mpl_utils.
plot_simple_scatter
(x: Sequence[float], y: Sequence[float], ax: Optional[matplotlib.axes._axes.Axes] = None, equal_aspect: bool = True, set_lim: bool = True, show_y_x_line: bool = True, xy_line_kwargs: dict = {}, **kwargs) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Plot a simple scatter plot of x vs. y on ax
See the matplotlib documentation for more keyword arguments and details: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter
Parameters: - {x,y} (typing.Sequence[float]) – The values to plot
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- equal_aspect (bool) – Whether to set the aspect of the axis to equal
- set_lim (bool) – Whether to automatically set the min and max axis limits
- show_y_x_line (bool) – Whether to draw the y=x line. This will look weird if set_lim is False.
- xy_line_kwargs (typing.Mapping) – keyword arguments for plotting the y=x line, if it plotting
- **kwargs (<key>=<value> pairs) –
Additional keyword arguments to pass to the scatter function. Some useful keyword arguments are:
- label : the label for a legend
- marker : https://matplotlib.org/examples/lines_bars_and_markers/marker_reference.html
Returns: - fig (matplotlib.figure.Figure) – The figure on which the scatter points were plotted
- ax (matplotlib.axes.Axes) – The axis on which the scatter points were plotted
-
pyllars.mpl_utils.
plot_sorted_values
(values: Sequence[float], ymin: Optional[float] = None, ymax: Optional[float] = None, ax: Optional[matplotlib.axes._axes.Axes] = None, scale_x: bool = False, **kwargs) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Sort values and plot them
Parameters: - values (typing.Sequence[float]) – The values to plot
- y_{min,max} (float) – The min and max values for the y-axis. If not given, then these default to the minimum and maximum values in the list.
- scale_x (bool) – If True, then the x values will be equally-spaced between 0 and 1. Otherwise, they will be the values 0 to len(values)
- ax (typing.Optional[matplotlib.axes.Axes]) – An axis for plotting. If this is not given, then a figure and axis will be created.
- **kwargs (<key>=<value> pairs) –
Additional keyword arguments to pass to the plot function. Some useful keyword arguments are:
- label : the label for a legend
- lw : the line width
- ls : https://matplotlib.org/gallery/lines_bars_and_markers/line_styles_reference.html
- marker : https://matplotlib.org/examples/lines_bars_and_markers/marker_reference.html
Returns: - fig (matplotlib.figure.Figure) – The Figure associated with ax, or a new Figure
- ax (matplotlib.axes.Axes) – Either ax or a new Axis
-
pyllars.mpl_utils.
plot_stacked_bar_graph
(ax, data, colors=<matplotlib.colors.LinearSegmentedColormap object>, x_tick_labels=None, stack_labels=None, y_ticks=None, y_tick_labels=None, hide_first_ytick=True, edge_colors=None, showFirst=-1, scale=False, widths=None, heights=None, y_title=None, x_title=None, gap=0.0, end_gaps=False, show_legend=True, legend_loc='best', legend_bbox_to_anchor=None, legend_ncol=-1, log=False, font_size=8, label_font_size=12, legend_font_size=8)[source]¶ Create a stacked bar plot with the given characteristics.
This code is adapted from code by Michael Imelfort.
-
pyllars.mpl_utils.
plot_trend_line
(x: Sequence[float], intercept: float, slope: float, power: float, ax: Optional[matplotlib.axes._axes.Axes] = None, **kwargs) → Tuple[matplotlib.figure.Figure, matplotlib.axes._axes.Axes][source]¶ Draw the trend line implied by the given coefficients.
Parameters: - x (typing.Sequence[float]) – The points at which the function will be evaluated and where the line will be drawn
- {intercept,slope,power} (float) – The coefficients of the trend line. Presumably, these come from
pyllars.stats_utils.fit_with_least_squares()
or something similar. - ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- **kwargs (<key>=<value> pairs) – Keyword arguments to pass to the ax.plot function (color, etc.). Please consult the matplotlib documentation for more details: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D
Returns: - fig (matplotlib.figure.Figure) – The figure on which the trend line was plotted
- ax (matplotlib.axes.Axes) – The axis on which the trend line was plotted
-
pyllars.mpl_utils.
plot_venn_diagram
(sets: Union[Mapping, Sequence], ax: Optional[matplotlib.axes._axes.Axes] = None, set_labels: Optional[Sequence[str]] = None, weighted: bool = False, use_sci_notation: bool = False, sci_notation_limit: float = 999, labels_fontsize: int = 14, counts_fontsize: int = 12) → matplotlib_venn._common.VennDiagram[source]¶ Wrap the matplotlib_venn package.
Please consult the package documentation for more details: https://github.com/konstantint/matplotlib-venn
N.B. Unlike most of the other high-level plotting helpers, this function returns the venn diagram object rather than the figure and axis objects.
Parameters: - set (typing.Union[typing.Mapping,typing.Sequence]) –
If a dictionary, it must follow the conventions of matplotlib_venn. If a dictionary is given, the number of sets will be guessed based on the length of one of the entries.
If a sequence is given, then it must be of length two or three.
The type of venn diagram will be based on the number of sets.
- ax (typing.Optional[matplotlib.axes.Axes]) – The axis. If not given, then one will be created.
- set_labels (typing.Optional[typing.Sequence[str]]) – The label for each set. The order of the labels must match the order of the sets.
- weighted (bool) – Whether the diagram is weighted (in which the size of the circles in the venn diagram are based on the number of elements) or unweighted (in which all circles are the same size)
- use_sci_notation (bool) – Whether to convert numbers to scientific notation
- sci_notation_limit (float) – The maximum number to show before switching to scientific notation
- {labels,counts}_fontsize (int) – The respective font sizes
Returns: venn_diagram – The venn diagram
Return type: matplotlib_venn._common.VennDiagram
- set (typing.Union[typing.Mapping,typing.Sequence]) –
-
pyllars.mpl_utils.
set_label_fontsize
(ax: matplotlib.axes._axes.Axes, fontsize: Union[int, str], axis: str = 'both') → None[source]¶ Set the font size of the labels of the axis.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- fontsize (int, or a str recognized by matplotlib) – The size of the label font
- axis (str in {both, x, y}) – Which label(s) to update
Returns: Return type: None, but the respective label fontsizes are updated
-
pyllars.mpl_utils.
set_legend_fontsize
(ax: matplotlib.axes._axes.Axes, fontsize: Union[int, str]) → None[source]¶ Set the font size of the items of the legend.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- fontsize (int, or a str recognized by matplotlib) – The size of the legend text
Returns: Return type: None, but the legend text fontsize is updated
-
pyllars.mpl_utils.
set_legend_title_fontsize
(ax: matplotlib.axes._axes.Axes, fontsize: Union[int, str]) → None[source]¶ Set the font size of the title of the legend.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- fontsize (int, or a str recognized by matplotlib) – The size of the legend title
Returns: Return type: None, but the legend title fontsize is updated
-
pyllars.mpl_utils.
set_ticklabel_rotation
(ax: matplotlib.axes._axes.Axes, rotation: Union[int, str], axis: str = 'x', which: str = 'both')[source]¶ Set the rotation of the tick labels
Parameters: - ax (matplotlib.axes.Axes) – The axis
- rotation (int, or a string matplotlib recognizes) – The rotation of the labels
- {axis,which} (str) – Values passed to
matplotlib.pyplot.setp()
. Please see the matplotlib documentation for more details.
Returns: Return type: None, but the ticklabels are rotated
-
pyllars.mpl_utils.
set_ticklabels_fontsize
(ax: matplotlib.axes._axes.Axes, fontsize: Union[int, str], axis: str = 'both', which: str = 'major')[source]¶ Set the font size of the tick labels
Parameters: - ax (matplotlib.axes.Axes) – The axis
- fontsize (int, or a str recognized by matplotlib) – The size of the ticklabels
- {axis,which} (str) – Values passed to
matplotlib.axes.Axes.tick_params()
. Please see the matplotlib documentation for more details.
Returns: Return type: None, but the ticklabel fontsizes are updated
-
pyllars.mpl_utils.
set_title_fontsize
(ax: matplotlib.axes._axes.Axes, fontsize: Union[int, str]) → None[source]¶ Set the font size of the title of the axis.
Parameters: - ax (matplotlib.axes.Axes) – The axis
- fontsize (int, or a str recognized by matplotlib) – The size of the title font
Returns: Return type: None, but the title fontsize is updated