import pandas as pd
# Download and prepare the data.
climate = pd.read_csv('climate_data.csv')
climate['Average temperature (°C)'] = (climate['Average temperature (°F)']-32)/1.800
climate['Year'] = climate['Date'].str[:4]
climate = climate[climate['Year']=='2020']
shrimps = pd.read_csv('shrimp-prices.csv')
shrimps['Year'] = shrimps['Month'].str[-4:]
shrimps = shrimps.groupby(['Year']).mean().reset_index(drop=False)
population = pd.read_csv('population_by_country_2020.csv')
population = population.sort_values(['Density (P/Km²)'], ascending=False)[:10]
import toyplot
x = climate['Average temperature (°C)']
y = climate['Average humidity (%)']
canvas = toyplot.Canvas(width=500, height=350)
axes = canvas.cartesian()
mark = axes.scatterplot(x, y)
canvas, axes, mark = toyplot.scatterplot(x, y, width=500, height=350,
label='Temperature vs. Humidity (Estes Park, 2020)',
xlabel='Temperature, °C',
ylabel='Humidity, %',
size=10, opacity=0.4,
color='slateblue', marker='s')
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
y1 = climate['Average humidity (%)']
y2 = climate['Minimum humidity (%)']
canvas = toyplot.Canvas(width=500, height=350)
axes = canvas.cartesian(label='Temperature vs. Humidity (Estes Park, 2020)',
xlabel='Temperature, °C',
ylabel='Humidity, %')
mark = axes.scatterplot(x, y1,
size=10, opacity=0.4,
title='Average humidity')
mark = axes.scatterplot(x, y2,
size=10, opacity=0.4,
title='Minimum humidity')
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
canvas = toyplot.Canvas(width=600, height=300)
axes = canvas.cartesian(grid=(1,2,0),
label='Temperature vs. Average humidity',
xlabel='Temperature, °C',
ylabel='Average humidity, %',
ymin=0, ymax=100)
mark = axes.scatterplot(x, y1, size=10, opacity=0.4)
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
axes = canvas.cartesian(grid=(1,2,1),
label='Temperature vs. Minimum humidity',
xlabel='Temperature, °C',
ylabel='Minimum humidity, %',
ymin=0, ymax=100)
mark = axes.scatterplot(x, y2, size=10, opacity=0.4)
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
x = shrimps['Year']
y = shrimps['Price']
canvas, axes, mark = toyplot.plot(x, y, width=550, height=350,
label='Shrimp prices by year',
xlabel='Year',
ylabel='Price, USD/kg')
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
canvas, axes, mark = toyplot.plot(x, y, width=550, height=350,
label='Shrimp prices by year',
xlabel='Year',
ylabel='Price, USD/kg',
style={'stroke':'dodgerblue',
'stroke-dasharray':'5',
'stroke-width':'4'})
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 15
heights = population['Density (P/Km²)']
canvas, axes, mark = toyplot.bars(heights, width=550, height=350,
label='TOP10 countries by population density in 2020',
xlabel='Countries',
ylabel='Population density, P/km²')
countries = list(population['Country (or dependency)'])
canvas, axes, mark = toyplot.bars(heights, width=500, height=350,
along='y',
margin=(45,20,45,62),
label='TOP10 countries by population density in 2020',
xlabel='Population density, P/km²')
axes.y.ticks.locator = toyplot.locator.Explicit(labels=countries)
axes.y.ticks.labels.angle = 270
axes.y.ticks.labels.offset = 52
axes.y.spine.show = False