Line Plot
Line plots of pre-aggregated data, with one line per value column or group value.
For x-axes that are relative or sequential values ("days since an event", "months since a
competitor opened"), use line.plot. For an actual datetime x-axis use plots.time, which
resamples and aggregates; this module does not aggregate, so pass one row per x value per line.
plot(df, value_col=None, x_label=None, y_label=None, title=None, eyebrow=None, subtitle=None, x_col=None, group_col=None, ax=None, source_text=None, legend_title=None, move_legend_outside=False, legend_style=None, fill_na_value=None, highlight=None, **kwargs)
Plot value_col over x_col or the index, with a separate line per unique group_col value.
When df is a Series, its values are plotted against its index and value_col,
x_col, and group_col must all be None. For a DataFrame, value_col is required,
and a list of columns cannot be combined with group_col.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | Series
|
The dataframe or series to plot. |
required |
value_col
|
str | list[str]
|
The column(s) to plot; a list renders one line per
column. Required when |
None
|
x_label
|
str
|
X-axis label; omitted means no label. |
None
|
y_label
|
str
|
Y-axis label; omitted means no label. |
None
|
title
|
str
|
The title of the plot. |
None
|
eyebrow
|
str
|
Small uppercase label rendered above the title. |
None
|
subtitle
|
str
|
Supporting copy rendered below the title. |
None
|
x_col
|
str
|
The column to use as the x-axis. If None, the index is used. |
None
|
group_col
|
str
|
The column used to define different lines. |
None
|
ax
|
Axes
|
Matplotlib axes object to plot on. |
None
|
source_text
|
str
|
The source text to add to the plot. |
None
|
legend_title
|
str
|
The title of the legend. |
None
|
move_legend_outside
|
bool
|
Move the legend outside the plot. |
False
|
legend_style
|
Literal['box', 'end_of_line']
|
How series are labelled. |
None
|
fill_na_value
|
float
|
Value for missing points, including x values a group has no
row for. Applied only when |
None
|
highlight
|
str | list[str]
|
Line(s) to emphasize; only for multi-line plots. With
|
None
|
**kwargs
|
Any
|
Additional keyword arguments for pandas' |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
SubplotBase |
SubplotBase
|
The matplotlib axes object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value_col is a list and group_col is provided. |
ValueError
|
If df is a Series and value_col is not None. |
ValueError
|
If df is a Series and x_col is specified (the Series index is the x-axis). |
ValueError
|
If df is a Series and group_col is specified (cannot group a single series). |
ValueError
|
If df is a DataFrame and value_col is None. |
ValueError
|
If highlight is provided for a single-line plot. |
ValueError
|
If highlight is an empty list. |
ValueError
|
If highlight values do not match available groups/columns. |
ValueError
|
If legend_style is not one of |
Source code in openretailscience/plots/line.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |