chatviz.plotting.plot_donuts

chatviz.plotting.plot_donuts(df, ax=None, colors='default', show_ylabels=False)

Creates a plot of 3 donut charts.

The donut charts contain the following info:

  1. The number of messages per person.

  2. The number of words per person.

  3. The number of characters per person.

Parameters
dfpd.DataFrame

The dataframe of messages. Must have the columns [‘date’, ‘text’, ‘name’].

axplt.Axes or None

This should be an iterable of 3 axes, such as the one generated from _, ax = plt.subplots(1, 3). If None (default), will create 3 new axes.

colors{‘default’} or list of str or dict

The colors to be used for each person in the chat. Should be either:

  • ‘default’ in which case the default color scheme is used

  • a list of colors the same length as the number of names in df[‘name’]

or

  • a dict which maps each name to a color.

For more info about the possible color strings, see the matplotlib documentation.

show_ylabelsbool

If True, will show names around the donut. If False (default), then they will be hidden.

Returns
array of plt.Axes objects

An array of length 3.

Examples

import matplotlib.pyplot as plt

from chatviz.plotting import plot_donuts
from chatviz.utils import load_example_chat_data

plt.rcParams["font.size"] = 25
plt.rcParams["axes.titlesize"] = 40
plt.rcParams["figure.figsize"] = [12, 30]
plt.rcParams["font.family"] = "Purisa"

df = load_example_chat_data()
fig, ax = plt.subplots(3, 1)
palette = ["#20639B", "#3CAEA3", "#F6D55C", "#ED553B", "#173F5F"]
plot_donuts(df, show_ylabels=True, ax=ax, colors=palette)
plt.subplots_adjust(hspace=0.4, top=0.95, bottom=0)
plt.show()

(Source code, png, hires.png, pdf)

../_images/donuts_example.png