【问题标题】:Plot and rearrange values in ascending order in seaborn [duplicate]在seaborn中按升序绘制和重新排列值[重复]
【发布时间】:2021-03-03 12:20:22
【问题描述】:

我希望 x 和 y 轴都按升序绘制值

代码

color_dict = dict({'1':'orange',
                  '2':'steelblue',
                  '3':'lightgreen', 
                   '4': 'purple'
                  })    

sns.set_style("whitegrid", {'grid.linestyle': '-'})
plt.figure(figsize=(12,8))

ax1=sns.scatterplot(data=df2, x="x", y="y", hue="result",markers= 'x',s=950, palette= color_dict )
#ax1.set(xlabel=None, ylabel=None, xticklabels=[], yticklabels=[])
#ax1.set_yticks((0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5), minor=0)
#ax1.set_xticks([0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.6], minor=False)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.setp(ax1.get_legend().get_texts(), fontsize='14') # for legend text
ax1.plot()

情节

目标

【问题讨论】:

  • 你的 x 和 y 可能是字符串而不是数字

标签: pandas matplotlib seaborn


【解决方案1】:

将数据类型更改为intfloat

df['x'] = df['x'].astype(int)
df['y'] = df['y'].astype(int)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2023-01-19
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    相关资源
    最近更新 更多