I am making a choropleth graph on Plotly Express in Python to map the Government Respond on COVID-19; particularly in Africa.
The data source can be found here.
It is an Oxford University dataset on Government Respond Tracker.
The example of the data source content (for your convenience):
CountryName|CountryCode|Date |...|EconomicSupportIndexForDisplay
Algeria | DZA |20200101 |...| 0
Algeria | DZA |20200102 |...| 0
.........................................
Algeria | DZA |20200724 |...| 50
.........................................
In actuality, there are 42 columns with 30,000+ rows; where these rows are updated daily.
However, not all of the countries are equally up to date (source Oxford GitHub page)
In my case, I have already build a database from it in PostgreSQL.
This is my code so far;
import psycopg2
import pandas as pd
import plotly.express as px
''' PostgreSQL Variables '''
# PostgreSQL Login Variables (edited out)
''' PostgreSQL Connection '''
# PostgreSQL DB Connection code (edited out)
African_Query = pd.read_sql_query(
'''
# SQL Query to pull all African countries from the DB (e.g. 'Algeria, 'Angola', 'Benin', 'etc')
''', conn)
# except ('Comoros', 'Equatorial Guinea', 'Guinea Bissau', and 'Sao Tome and Principe')
# those countries were not exist in the datasource
African = pd.DataFrame(African_Query,
columns=['all column names from the datasource'])
''' Plotly graph '''
# Government Respond - School Closing
african_figure1 = px.choropleth(African,
locations="countrycode",
color="c1_school_closing",
color_continuous_scale="Blues",
range_color=[0, 3],
hover_data={"c1_school_closing": False,
"countrycode": False,
"countryname": False},
hover_name="countryname",
labels={"c1_school_closing": "SCALE"})
african_figure1.update_layout(geo_scope='africa',
title_text="Government Respond - SCHOOL CLOSING")
african_figure1.show()
The map is successfully created. Now I wanted to do the following things;
- I wanted to change the color that I used. From initially using the in-built color picker in Plotly to one of the CSS style color. For instance into the (#4c5c73)
*edit: I have been trying to modify the value in the 'color_continuous_scale="some_color_value"', to no avail.
Or was I wrong to edit this?
Many thanks for your time!

