![](/img/trans.png)
[英]Is there a way to make the font size of a label dynamicly adjust to the text thats put in the label In PyQt5?
[英]adjust the size of the text label in plotly
我正在嘗試根據國家/地區大小調整文本大小,因此文本將位於國家的版塊內。
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()
對於可視化:
橙色國家/地區的文字在該國家/地區的板內,但藍色國家/地區 label 的文字更大。
最好是調整大小,這樣它就不會超過國家的邊界
您可以使用 update_layout function 設置字體大小,並通過在字體參數中傳遞字典來指定字體大小。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.