调整plotly中文本标签的大小

Gre*_*lor 13 python plotly choropleth

我正在尝试根据国家/地区大小调整文本大小,因此文本将位于国家/地区的董事会内部。

import pandas as pd
import plotly.express as px

df=pd.read_csv('regional-be-daily-latest.csv', header = 1)

fig = px.choropleth(df, locations='Code', color='Track Name')
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

fig.add_scattergeo(

  locations = df['Code'],
  text = df['Track Name'],
  mode = 'text',
)

fig.show()
Run Code Online (Sandbox Code Playgroud)

对于可视化:

在此输入图像描述

橙色国家的文本位于该国家/地区的棋盘内,但标记蓝色国家的文本更大。

最好是调整大小,这样它就不会超过国家的董事会

Tri*_*hwa 20

您可以使用 update_layout 函数设置字体大小,并通过在 font 参数中传递字典来指定字体大小。

import pandas as pd
import plotly.express as px

df=pd.read_csv('regional-be-daily-latest.csv', header = 1)

fig = px.choropleth(df, locations='Code', color='Track Name')
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

fig.add_scattergeo(

  locations = df['Code'],
  text = df['Track Name'],
  mode = 'text',
)


fig.update_layout(
    font=dict(
        family="Courier New, monospace",
        size=18,  # Set the font size here
        color="RebeccaPurple"
    )
)

fig.show()
Run Code Online (Sandbox Code Playgroud)