Visualization in Python
Visualization in Python
Python
THE CONTRACTOR IS ACTING UNDER A FRAMEWORK CONTRACT CONCLUDED WITH THE COMMISSION
Eurostat
Outline
2
Eurostat
Which packages/functions
3
Eurostat
ggplot
qplot(diamonds.carat, diamonds.price)
5
Eurostat
Aesthetics
Mapping of data to
visual attributes of
geometric objects:
– Position: x, y
– Color: color
– Shape: shape
Mapping of data to
visual attributes of
geometric objects:
– Position: x,y
– Color: color
– Shape: shape
• Geometric objects:
• Points, lines, polygons, …
• Functions start with “geom_”
• Also margins:
• geom_errorbar(), geom_pointrange(),
geom_linerange().
• Note: they require the aesthetics ymin and
ymax.
9
Eurostat
stat_smooth
12
Eurostat
scale_x_log
df = pd.DataFrame({"x": np.arange(100)})
df['y'] = df.x * 10 # polar coords
p = ggplot(df, aes(x='x', y='y')) + geom_point() + coord_polar()
print(p)
14
Eurostat
Facets
ggplot(diamonds, aes(x='price')) + \
geom_histogram() + \
facet_grid("cut")
15
Eurostat
Facets example
ggplot(chopsticks, aes(x='chopstick_length',
y='food_pinching_effeciency')) + \
geom_point() + \
geom_line() + \
scale_x_continuous(breaks=[150, 250, 350]) + \
facet_wrap("individual") 16
Eurostat
Facets
example 2
g.save(“myimage.png”)
18
Eurostat
Folium: Thematic maps
• A thematic map is a visualization where statistical
information with a spatial component is shown.
• Other libraries are: Basemap, Cartopy, Iris
• Folium builds on the data wrangling strengths of
the Python ecosystem and the mapping strengths
of the Leaflet.js library.
• Manipulate your data in Python, then visualize it
in on a Leaflet map via Folium.
19
Eurostat
Folium features
• Built-in tilesets from OpenStreetMap, MapQuest
Open, MapQuest Open Aerial, Mapbox, and
Stamen
• Supports custom tilesets with Mapbox or Cloudmade API
keys.
• Supports GeoJSON and TopoJSON overlays,
• as well as the binding of data to those overlays to create
choropleth maps with color-brewer color schemes.
20
Eurostat
Basic Maps
25
Eurostat
References
• http://yhat.github.io/ggplot/
• https://folium.readthedocs.io/en/latest/
26
Eurostat