Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: Australia Choropleth map

I am having a list of states and territories of Australia with their corresponding values. Now I want to produce a heat map like this:

enter image description here

I am following the examples with Pyplot from this link but it just has an example for states in the US.

enter image description here

In particular, in this block of code:

data = [ dict(
    type='choropleth',
    colorscale = scl,
    autocolorscale = False,
    locations = df['code'],
    z = df['total exports'].astype(float),
    locationmode = 'USA-states',
    text = df['text'],
    marker = dict(
        line = dict (
            color = 'rgb(255,255,255)',
            width = 2
        ) ),
    colorbar = dict(
        title = "Millions USD")
    ) ]

layout = dict(
    title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)',
    geo = dict(
        scope='usa',
        projection=dict( type='albers usa' ),
        showlakes = True,
        lakecolor = 'rgb(255, 255, 255)'),
         )

How can I modify the code to match my requirement? What should be the correct values for parameters locations, locationmode, scope, projection in case of Australia map? Like how can I find out the code for Australia's states, territories, and cities if I have their names?

Any pointers will be appreciated. Other library recommendations will also be considered.

like image 786
Forrest Avatar asked Apr 24 '18 17:04

Forrest


1 Answers

I tried to do something similar a few months back, and unfortunately Plotly doesn't currently offer any even half decent resolution maps of Australia (or any country other than the USA).

If you refer to the Plotly API, the only locationmode options available are ["ISO-3" | "USA-states" | "country names"]

To plot any country that's not the USA the only option is to use locationmode = "country names", as is the case in the Western Africa example, and set a:

geo = dict(
    scope = 'australia'
)

However, what you will find is that the coast lines are all jagged and look terrible, there's no option for state boundaries etc.

The best option I've been able to find after a fairly uninspiring search is using matplotlib and Basemap. E.g. this tutorial.

It seems like Basemap offers a huge range of mapping options, so hopefully you can find some love there.

Alternatively, if your values are state-wide, I'd just use the cool little web-based tool offered by Socialcops.

like image 173
David Norrish Avatar answered Oct 20 '22 13:10

David Norrish