【问题标题】:How to avoid scientific notation when annotating a seaborn clustermap?注释seaborn clustermap时如何避免科学记数法?
【发布时间】:2015-09-12 08:27:28
【问题描述】:

我有一个包含百分比的数据框。如果我使用 seaborn 来制作 clusterplot,则数字 100 被绘制为 1+e01

有什么办法可以避免吗?

我尝试在绘制百分比之前对其进行四舍五入,但这不会影响绘图。

【问题讨论】:

    标签: python pandas seaborn


    【解决方案1】:

    使用fmt="d",如this example

    import seaborn as sns
    sns.set()
    
    flights_long = sns.load_dataset("flights")
    flights = flights_long.pivot("month", "year", "passengers")
    flights = flights.reindex(flights_long.iloc[:12].month)
    
    sns.heatmap(flights, annot=True, fmt="d")
    

    fmtheatmap 的参数,但额外的 clustermap kwargs 会传递到主热图。

    【讨论】:

    • 除了使用"d"之外还有其他方法吗?我在使用 numpy 的浮点数组时遇到问题。如果可能,我想避免使用array.astype(int),因为我希望nan 值不会显示在热图中。编辑:好的,我发现"g" 有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2021-09-13
    • 1970-01-01
    相关资源
    最近更新 更多