Hi, Plotly community!
A nice graphing tool that you have here.
However, I have a question as a newbie using the Plotly Express choropleth visual.
Also, I would like to apologize for the length of this question in advance!
So, I am making a choropleth graph on Plotly Express (Python version) to map the Government Respond on COVID-19; particularly in Africa.
If any of you wondering about the data source, you can find it here, Oxford University data source.
For your convenience, some example of the content of this data source:
CountryName|CountryCode| Date |...|EconomicSupportIndexForDisplay
Algeria | DZA |20200101 |...| 0
Algeria | DZA |20200102 |...| 0
.............................................................
Algeria | DZA |20200724 |...| 50
............................................................
TLDR; there are 42 columns with 30,000+ rows; where these rows are updated daily.
However, not all of the countries in the dataset are equally up to date (source: Oxford University GitHub page).
For my case, I have already created my database of that dataset in PostgreSQL.
I have written this code so far but struggling to progress further.
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
''' Load SQL Queries into Pandas DataFrame '''
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()
I wanted to change the colour used on my choropleth graph into using CSS style.
In this case, I want to use a CSS colour with the following code #4c5c73.
So far, I have been reviewing the documentation on colorscales and the choropleth.
There is indeed a trace of the use of CSS colour in choropleth_mapbox
.
But, this is not what I am looking for.
Thus, Plotly community could you please help me figured out the fix for this?
Many thanks for your time and again, I apologize for the length of this question.
Best,
Aldy