gpt4 book ai didi

python - Pandas 缺少 x 刻度标签

转载 作者:太空狗 更新时间:2023-10-30 00:59:14 34 4
gpt4 key购买 nike

当我将 c 添加到 pandas plot 时,x 刻度标签消失了。有谁知道如何将它们加回来?

import pandas as pd

df = pd.DataFrame(
{'mean': {0: 10,
1: 16,
2: 18,
3: 22,
4: 30},
'size': {0: 103, 1: 2509, 2: 41939, 3: 145997, 4: 143530},
'value': {0: 1.5, 1: 4.5, 2: 7.5, 3: 10.5, 4: 13.5}}
)

ax = df.plot(kind='scatter', x='value', y='mean', s=60, c='size', cmap='RdYlGn')

enter image description here

尝试手动添加 x 个刻度标签,但仍然无效。

ax.set_xticks(df['value'])
ax.set_xticklabels(df['value'])

最佳答案

好吧,我认为这是 pandas plot 的一个错误。然而,这SO post显示以下解决方法。

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(
{'mean': {0: 10,
1: 16,
2: 18,
3: 22,
4: 30},
'size': {0: 103, 1: 2509, 2: 41939, 3: 145997, 4: 143530},
'value': {0: 1.5, 1: 4.5, 2: 7.5, 3: 10.5, 4: 13.5}}
)
fig, ax = plt.subplots()
df.plot(kind='scatter', x='value', y='mean', s=60, c='size', cmap='RdYlGn', ax=ax)

enter image description here

关于python - Pandas 缺少 x 刻度标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578976/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com