[英]Plotly: How to set choropleth map color for a discrete categorical variable?
[英]Plotly: How to set colorbar position for a choropleth map?
我在文檔中找不到任何關於控制顏色條的放置位置、是否應該顯示以及使用什么色標等的信息。可以這樣做嗎?
如果有幫助,我正在用 Dash 實現我的 choropleth map。
fig.data[0].colorbar.x=-0.1
或者:
fig.update_layout(coloraxis_colorbar_x=-0.1)
您尚未提供任何代碼,因此我將參考文檔中的示例,其中沿 x 軸的顏色條的 position 默認為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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.