我在文档中找不到任何有关控制颜色条放置位置,是否应该显示颜色条以及使用哪种色标等的信息。可以这样做吗?
如果有帮助,我正在用Dash实现我的Choropleth贴图。
fig.data[0].colorbar.x=-0.1
此处,颜色栏沿x轴的位置默认为1.2
。您可以通过以下方式直接更改它:
fig.data[0].colorbar.x=-0.1
得到:
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')
fig = go.Figure(data=go.Choropleth(
locations=df['code'], # Spatial coordinates
z = df['total exports'].astype(float), # Data to be color-coded
locationmode = 'USA-states', # set of locations match entries in `locations`
colorscale = 'Reds',
colorbar_title = "Millions USD",
))
fig.update_layout(
title_text = '2011 US Agriculture Exports by State',
geo_scope='usa', # limite map scope to USA
)
fig.data[0].colorbar.x=-0.1
fig.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句