plot¶
pltviz provides standardized versions of common Python plotting methods.
Functions
- pltviz.bar(counts, labels=None, faction_labels=None, colors=None, horizontal=False, stacked=False, label_bars=False, dsat=0.95, axis=None)[source]¶
A customizable bar plot that allows for easy combination of inputs into factions.
- Parameters:
- countslist or list of lists (contains ints or floats)
The data to be plotted.
Note: a list of lists produces a stacked plot where sublists define factions to be stacked.
- labelslistoptional (default=None; contains strs)
The labels of the groups.
- faction_labelslistoptional (default=None; contains strs)
The labels of potential factions.
Note: plotting with factions groups bars based on the list in which they’re found.
- colorslistoptional (default=None)
The colors of the groups as hex keys.
- horizontalbooloptional (default=False)
Whether the plot should be horizontal.
- stackedbooloptional (default=False)
Whether the outputs should be stacked.
Note: the use of faction_labels will inherently stack faction members and separate factions.
- label_barsbooloptional (default=False)
Whether or not to label the bars with their heights (or widths).
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- axisstroptional (default=None)
Adds an axis to plots so they can be combined.
- Returns:
- axmatplotlib.pyplot.subplot
A bar plot with the above criteria.
- pltviz.comp_line(df=None, dependent_cols=None, indep_stats=None, group_col=None, colors=None, stacked=False, percent=False, dsat=0.95, axis=None)[source]¶
Plots a line plot to compare statistics over a changing baseline.
- Parameters:
- dfpd.DataFrame
Dataframe that contains statistics to be compared.
- dependent_colsstr or list (contains strs) (default=None)
The column(s) in df which should be compared.
- indep_statsstr or list (contains ints or floats) (default=None)
A df column or the baseline stats that generated the columns in dependent_cols.
- group_colstr (default=None)
The name of the column in which groups are defined.
Note: this allows plotting across multiple instances in a single column.
- colorslist or list of listsoptional (default=None)
The colors of the groups as hex keys.
- stackedbool (default=False)
Whether the plot is a stackplot.
- percentbool (default=False)
Whether the y-axis should depict relative amounts or not.
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- axisstroptional (default=None)
Adds an axis to plots so they can be combined.
- Returns:
- axmatplotlib.pyplot.subplot
A line plot that shows the shifts in group allocations given seat limits.
- pltviz.gini(shares=None, dsat=0.95, axis=None)[source]¶
Produces a semicircle plot of shares or allocations.
- Parameters:
- shareslist (contains ints or floats)
The data to be plotted.
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- axisstroptional (default=None)
Adds an axis to plots so they can be combined.
- Returns:
- ax, ginimatplotlib.pyplot.subplot, float
A gini plot of dispropotionality and the area under the Lorenz curve.
- pltviz.legend.gen_handles(colors=None, size=10, marker='o', dsat=0.95)[source]¶
Generates handles for plot legends.
- Parameters:
- colorslist (contains rgb strs)
The colors to be used for the legend.
- sizeint or float (default=10)
The size of the markers for the legend.
- markerstroptional (default=’o’)
The kind of shape for the legend (takes matplotlib.marker types).
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- Returns:
- lgnd_handleslist (countains unplotted 2D lines)
A list of lines, the handles of which can be used for more advanced plots.
- pltviz.legend.gen_elements(counts=None, labels=None, colors=None, size=10, marker='o', padding_indexes=None, order=None, dsat=0.95)[source]¶
Generates handles and labels for plot legends while allowing for label padding and reordering.
- Parameters:
- countslist or list of listsoptional (contains ints or floats)
The data to be plotted.
- labelslistoptional (default=None; contains strs)
The labels of the groups.
- colorslistoptional (contains rgb strs)
The colors to be used for the legend.
- sizeint or float (default=10)
The size of the markers for the legend.
- markerstroptional (default=’o’)
The kind of shape for the legend (takes matplotlib.marker types).
- padding_indexesint or listoptional (default=None)
Which indexes in the label should be filled with blank space to organize it well.
- orderlistoptional (default=None)
The order for the handles and labels.
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- Returns:
- lgnd_handles, lgnd_labels: list (countains unplotted 2D lines) and list (contains strs)
A list of lines, the handles of which can be used for more advanced plots, as well as labels for the handles.
- pltviz.pie(counts, labels=None, faction_labels=None, colors=None, radius=1, outer_ring_density=100, donut_ratio=1, display_labels=False, display_counts=False, label_font_size=20, dsat=0.95, axis=None)[source]¶
Produces a donut plot of group (and faction) shares or allocations.
- Parameters:
- countslist or list of lists (contains ints or floats)
The data to be plotted.
Note: a list of lists produces a two layer plot where sublists define factions.
- labelslistoptional (default=None; contains strs)
The labels of the groups.
- faction_labelslistoptional (default=None; contains strs)
The labels of potential factions.
- colorslist or list of listsoptional (default=None)
The colors of the groups as hex keys.
- outer_ring_densityint (default=500)
The density of the faction ring gradients.
- radiusfloatoptional (default=1)
The size of the plot.
- donut_ratiofloat (default=1, a full circle)
The ratio of the center radius of a donut to the whole.
- display_labelsbooloptional (default=False)
Whether to display the labels of the groups (or factions if they’re included).
Note: labels can only be displayed for groups or factions, faction labels are if they’re included.
Note: if factions are included, then a legend should be used for the inner group labels (see package examples).
- display_countsbooloptional (default=False)
Whether to display the counts of the groups or factions.
- label_font_sizeint (default=20)
The size of the text in the labels.
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- axisstroptional (default=None)
Adds an axis to plots so they can be combined.
- Returns:
- axmatplotlib.pyplot.subplot
A donut plot that depicts shares or allocations (potentially including factions).
- pltviz.semipie(counts, colors=None, donut_ratio=1, dsat=0.95, axis=None)[source]¶
Produces a semicircle plot of shares or allocations.
- Parameters:
- countslist (contains ints or floats)
The data to be plotted.
- colorslist or list of listsoptional (default=None)
The colors of the groups as hex keys.
- donut_ratiofloat (default=1, a full semicircle)
The ratio of the center radius of a donut to the whole.
- dsatfloatoptional (default=default_sat)
The degree of desaturation to be applied to the colors.
- axisstroptional (default=None)
Adds an axis to plots so they can be combined.
- Returns:
- axmatplotlib.pyplot.subplot
A semicircle plot that depicts shares or allocations.