简体   繁体   English

1) 如何在 Pandas Bokeh 中切换科学记数法(使用 plot_bokeh 函数)和 2)如何将颜色居中于 0(所以白色为 0)

[英]1) How do I toggle scientific notation in pandas Bokeh (using the plot_bokeh function) and 2) how do I center the colours at 0 (so white is 0)

I have some dataframe like this:我有一些这样的数据框:

df = pd.DataFrame({
    'FSA': ['T9X', 'T2B', ...],
    'vals': [-1.1, 2.2, ...]
    'geometry': [some elements of type shapely.geometry.polygon.Polygon]
})

Where I got the geometry boundaries from the 2016 Canadian census here: http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfsa000a16a_e.zip我从 2016 年加拿大人口普查中获得几何边界的地方: http : //www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfsa000a16a_e.zip

And I am basically trying to make a census map with some statistics using this dataframe like so:我基本上是在尝试使用此数据框制作包含一些统计数据的人口普查地图,如下所示:

df.plot_bokeh(
      simplify_shapes=20000,
      category="vals",
      colormap='RdBu', 
      colormap_range=(np.min(df.vals), np.max(df.vals)),
      hovertool_columns=["FSA", "vals"],
      figsize=(800, 800),
      title='Vals per FSA'
  )

I've tried looking in the docs for Bokeh and all over the place and can't really find how to standardize the colours so 0 (white) is in the middle of the colours, and negative values are red/positive are blue.我试过查看散景和所有地方的文档,但无法真正找到如何标准化颜色,因此 0(白色)位于颜色的中间,负值是红色/正值是蓝色。 Also, how do I turn off scientific notation?另外,如何关闭科学记数法? Any help is much appreciated :)任何帮助深表感谢 :)

This doesn't help with creating a custom color ramp, but one thing you can do to "cheat" and put 0 in the middle and get it to be white is to use your min (or max, or some other arbitrary end point on either end, as long as they are the same) on both sides of of the colormap_range.这对创建自定义色带没有帮助,但是您可以做的一件事是“作弊”并将 0 放在中间并使其变为白色是使用您的最小值(或最大值,或其他任意端点)任一端,只要它们相同)在 colormap_range 的两侧。 So depending on how you want to represent the data (either way values will be clumped in one of the far ends of the color map).因此,取决于您想要如何表示数据(无论哪种方式,值都将聚集在颜色图的远端之一)。 So it's not an ideal solution but would be one way of doing it.所以这不是一个理想的解决方案,但会是一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM