【问题标题】:Bubble plot with NaN values具有 NaN 值的气泡图
【发布时间】:2022-01-11 11:33:41
【问题描述】:

我有一个这样的数据框:

x y height
1 1 NaN
2 5 20
3 10 100
4 7 NaN
5 6 NaN
6 12 500

我需要为 x-y 创建一个气泡图,其中“高度”作为点大小的变量(当它是 NaN 时使用其他标记)。

我正在尝试以这种方式调节高度变量,但没有成功。

fig = plt.figure()
ax = fig.add_subplot()

ax.scatter(x, y, marker='o', c='k', s=height)
ax.scatter(x[height==np.nan], y[height==np.nan], marker='^', c='r')

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python matplotlib nan colormap bubble-chart


【解决方案1】:

试试:

fig, ax = plt.subplots()

ax.scatter(df['x'], df['y'], marker='o', c='k', s=df['height'])

ax.scatter(df.loc[df['height'].isna(), 'x'], df.loc[df['height'].isna(), 'y'],
           marker='^', c='r')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 2018-06-13
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多