I'm uploading a spreadsheet from excel to a dataframe. In this table, I am only interested in two columns. The first column is the date and time in the format %Y-%m-%d %H-%M-%S. The second column is a categorical variable, namely the type of violation (for example, being late). There are few types of violations in total. About 6-7 types. Using the command df.info () you can make sure that the dataframe for the available columns has the datatime64[ns] type for the date and time column and the category type for the column with the types of violations. I would like to use hexbin plot with marginal distributions from the seaborn library (https://seaborn.pydata.org/examples/hexbin_marginals.html ). However, the simple code available at the link above is not so simple for a variable with categories and time.
import seaborn as sns
sns.set_theme(style="ticks")
sns.jointplot(x=df['incident'], y=['date-time'], kind="hex", color="#4CB391")
The compiler reports TypeError: The x variable is categorical, but one of ['numeric', 'datetime'] is required
I understand that either a numeric variable or a date-time variable is needed for the ordinate axis. Conversion does not solve the problem.
This error can be reproduced using
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
ndf = pd.DataFrame({'date-time': ['2021-11-15 00:10:00','2021-11-15 00:20:00'], 'incident': ['a','b']})
print(ndf)
sns.set_theme(style="ticks")
sns.jointplot(data=ndf, x='incident', y='date-time', color="#4CB391", hue=ndf['incident'] )
plt.show()
Question. How to get a plot looks like seabron style