Figure Friday 2025 - week 16

Thanks very much, in chemycal proccess :stuck_out_tongue_winking_eye:

1 Like

Hi Ester,

The way the pie chart interacts on hover is nice.

2 Likes

Hi @Ester

I think the message on your topcards would be stronger if you would convert it into something like:
180/500 = 36% of the households in the top-5 cat?-countries owns a cat.

Love the colors.

2 Likes

I didn’t want to put too much time into this as work is getting busy. But, I took a sec to make a figure. Ideally, I would like to have put charts on a map. But, for now, I settled for putting emoji symbols as annotations on the map. I scaled the symbol with fontsize as the percent ownership to a small exponent.

I then played with the hoverdata to give some information.

import plotly.graph_objects as go
import pandas as pd
import numpy as np

petdata = pd.read_csv('https://raw.githubusercontent.com/plotly/Figure-Friday/refs/heads/main/2025/week-16/pet_ownership_data_updated.csv')
petdata.loc[petdata['Country'] == 'USA','Country'] = 'United States'
petdata.loc[petdata['Country'] == 'UK','Country'] = 'United Kingdom'
petdata.loc[petdata['Country'] == 'Russia','Country'] = 'Russian Federation'
petdata = petdata.iloc[0:-1,:] #Drop the last row

petdata = petdata.sort_values(['Country'])
petdata = petdata.reset_index(drop=True)

countriesdf = pd.read_csv('https://raw.githubusercontent.com/gavinr/world-countries-centroids/refs/heads/master/dist/countries.csv')
#Append data for Hong Kong
new_row = pd.DataFrame(
    {
        "longitude": [114.16993426713121], 
        "latitude": [22.318764728315433],
        "COUNTRY": ['Hong Kong'],
        'ISO': ['HK'],
        'COUNTRYAFF': ['Hong Kong'],
        'AFF_ISO': ['HK'],
    }
)
countriesdf = pd.concat([countriesdf, new_row], ignore_index=True)
#Drop the rows of countriesdf that we don't care about
countriesdf = countriesdf.loc[countriesdf['COUNTRY'].isin(petdata['Country']),:]
countriesdf = countriesdf.sort_values(['COUNTRY'])
countriesdf = countriesdf.reset_index(drop=True)
petdata = pd.concat([petdata,countriesdf],axis=1)

petsymbols = {
    'Bird': "🐦",
    'Fish': "🐟",
    'Dog': "🐕",
    'Cat': "🐈"
}


fig = go.Figure()
for index, countryrow in petdata.iterrows():
    thepets = countryrow[['Dog','Cat','Fish','Bird',]].sort_values(ascending = False)
    
    thesymbols = [petsymbols[pet] for pet in  thepets.keys()]
    thesizes = [pct**1.26 for pct in thepets]
    country = countryrow.loc['Country']
    for i in range(4):#order the row
        petpct = thepets.iloc[i]
        thepet = thepets.keys()[i]+'s'
        if thepet == 'Fishs':
            thepet = 'Fish'
        textstring = f'{petpct}% of people own {thepet}'
        fig.add_trace(
            go.Scattergeo(
                lon=[countryrow['longitude']],# - (0.5*np.random.random(size=1)[0]-0.5)],
                lat=[countryrow['latitude'] - 0.75*float(i)],# - (2*np.random.random(size=1)[0]-0.5)],
                mode = "text",
                text = thesymbols[i], #["🐦", "🐟", "🐕", "🐈"], #order is bird, fish, dog, cat
                textfont = {'size': thesizes[i]},
                hovertemplate = "<b>"+country+":</b><br>"+textstring + "<extra></extra>"
            )
        )
fig.update_layout(
    showlegend = False,
    geo = dict(
        #resolution = 50,
        showland = True,
        showcountries = True,
        showocean = True,
        showlakes=False,
        countrywidth = 0.5,
        landcolor = 'rgb(253, 236, 199)',
        oceancolor = 'rgb(163, 213, 231)',
        projection = dict(
            type = 'orthographic',
            rotation = dict(
                lon = 0,
                lat = 40,
                roll = 0
            )
        ),
        center=dict(
            lat=45,
            lon=10,
        ),
        lataxis_range=[30,60],
        lonaxis_range=[-15,30],
    ),
    height = 1000,
    width = 1000,
)
fig.show()
6 Likes

what a creative way of showing pet ownership stats! Nice job, @ranknovice .

2 Likes

@marieanne I fixed what you wrote me in KPIs and I changed the yellow colors for blue. :slight_smile:

3 Likes

I just saw your nice images and flags:)