-
Hi, while categorical histplots generally work, they don't seem to work (properly) for boolean data. import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
if __name__ == '__main__':
df = pd.DataFrame({'y': [True, True, True, False, False]})
plt.figure()
# produces (undesired) float scale and the following message:
# <__array_function__ internals>:180: RuntimeWarning: Converting input from bool to <class 'numpy.uint8'> for compatibility.
sns.histplot(df, x='y')
df['y'] = df['y'].map({True: 'True', False: 'False'})
plt.figure()
# desired output (categorical scale)
sns.histplot(df, x='y')
plt.show() Produces the following two figures: This is with seaborn 0.12.1. (Unrelated, but - wouldn't it be nicer if the y axis showed integer, not float values, as these are count data?) |
Beta Was this translation helpful? Give feedback.
Answered by
mwaskom
Nov 29, 2022
Replies: 1 comment 1 reply
-
Numpy (and Python in general) upcasts boolean data to numeric dtypes where relevant (True/False are equivalent to 1/0). |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mwaskom
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Numpy (and Python in general) upcasts boolean data to numeric dtypes where relevant (True/False are equivalent to 1/0).