'plot a dataframe so that one column is a set of plotted signs as a function of the other columns | python

For the lack of a better explanation, I will add a picture. This is my dataframe:

df_for_plot
Out[403]: 
                           hour  dow  month  to
timestamp                                      
2019-06-24 00:00:00+00:00     0    0      6   1
2019-06-24 01:00:00+00:00     1    0      6   1
2019-06-24 02:00:00+00:00     2    0      6   1
2019-06-24 03:00:00+00:00     3    0      6   2
2019-06-24 04:00:00+00:00     4    0      6   2
                        ...  ...    ...  ..
2019-09-20 19:00:00+00:00    19    4      9   1
2019-09-20 20:00:00+00:00    20    4      9   1
2019-09-20 21:00:00+00:00    21    4      9   1
2019-09-20 22:00:00+00:00    22    4      9   1
2019-09-20 23:00:00+00:00    23    4      9   1

[34848 rows x 4 columns]

set(df_for_plot["to"])
Out[404]: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

I would like to plot something like this so that hour and dow are representing the values on the axis and the tocolumn will be plotted as a variable, represented by some signs, like in this visual example I quickly drew

enter image description here

Is there a way to do something like this in python?



Solution 1:[1]

You can use scatterplot from seaborn with pd.cut for grouping your values:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

rng = np.random.default_rng(2022)
df = pd.DataFrame({'hour': rng.integers(0, 24, 30),
                   'dow': rng.integers(0, 5, 30),
                   'to': rng.integers(0, 11, 30)})

df['cat'] = pd.cut(df['to'], [1, 4, 7, 10], labels=['1-3', '4-7', '8-10'], right=False)

ax = sns.scatterplot(data=df, x='hour', y='dow', hue='cat', style='cat')
plt.show()

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien