我正在制作px.choropleth()图表plotly.express。
这是代码片段;
import psycopg2
import pandas as pd
import plotly.express as px
''' PostgreSQL Variables '''
# your postgres login variables
''' PostgreSQL Connection '''
# your postgres connection code
''' SQL Query '''
# your SQL Query
''' Load SQL Queries into Pandas DataFrame '''
African = pd.DataFrame(SQL_Query_Code,
columns=['list-of-all-columns'])
''' Variable for Personal Colours '''
# e.g. HTML/HEx code : '#4c5c73'
# List all of the shades/tints codes; in this example I am using the tints codes
my_color_scale = [[0.0, '#4c5c73'], [0.1, '#5D6C81'], [0.2, '#6F7C8F'], [0.3, '#818C9D'], [0.4, '#939DAB'],
[0.5, '#A5ADB9'], [0.6, '#B7BDC7'], [0.7, '#C9CED5'], [0.8, '#DBDEE3'], [0.9, '#EDEEF1'],
[1.0, '#FFFFFF']]
''' Plotly graph '''
# Government Respond - School Closing
african_figure1 = px.choropleth(African,
locations='countrycode',
color='c1_school_closing',
color_continuous_scale=my_color_scale,
range_color=[0, 3],
hover_data={'c1_school_closing': False,
'countrycode': False,
'countryname': False},
hover_name='countryname',
labels={'c1_school_closing': 'SCALE'})
是否可以手动重命名由 ? 自动创建的图例px.choropleth?
慕少森
相关分类