【发布时间】:2021-03-04 15:56:16
【问题描述】:
我正在寻找一种描述性地分散pandas.DataFrame 的方法,类似于:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 type 1000 non-null object
1 value 1000 non-null int64
2 count 1000 non-null int64
dtypes: int64(2), object(1)
memory usage: 23.6+ KB
使用pandas.DataFrame.plot 或seaborn.scatterplot,每个type 的点都放置在一条垂直线上,彼此重叠。为了缓解这个问题,我想在 x 方向上至少引入一些抖动,但我不知道如何。
到目前为止我的情节:
import pandas as pd
import matplotlib.pyplot as plt
import random
df = pd.DataFrame({
'type': [random.choice(['t1', 't2', 't3']) for _ in range(1000)],
'value': [random.randint(0, 500) for _ in range(1000)],
'count': [random.randint(0,250) for _ in range(1000)],
})
df.plot(kind='scatter', x='type', y='value', c='count', cmap='Blues')
plt.show()
import seaborn as sns
sns.scatterplot(x='type', y='value', data=df, hue='count')
plt.show()
【问题讨论】:
标签: python dataframe matplotlib seaborn scatter-plot