Interactive Data Visualization with Python by Anshu Kumar & Shubhangi Hora & Sharath Chandra Guntuku & Abha Belorkar
Author:Anshu Kumar & Shubhangi Hora & Sharath Chandra Guntuku & Abha Belorkar [Anshu Kumar]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2019-10-23T16:00:00+00:00
Add the layer function from the altair library:import altair as alt
bars = alt.Chart().mark_bar().encode(
x='Region:N',
y='mean(Happy Planet Index):Q',
).properties(width=400)
line = alt.Chart().mark_rule(color='firebrick').encode(
y='mean(Happy Planet Index):Q',
size=alt.SizeValue(3)
)
alt.layer(bars, line, data=hpi_df)
The output is as follows:
Figure 4.20: Showing the mean on the bar plot
So, now we know that the mean Happy Planet Index across all regions is around 26. Looks like there's a lot more happiness that our planet could take. Interesting!
By the way, you should also note that we didn't specify the dataset until we used the layer function. That is, we did not provide the hpi_df dataset in the Chart() function as we would usually do. Instead, we mentioned it in the layer function with the data=hpi_df parameter.
Now that you know about the concept of layering in altair, you can be trusted with a shortcut for it. Just write code independently for different plots, as you would usually write it, then use the + operator, as shown in the following example!
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9379)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9347)
The Mikado Method by Ola Ellnestam Daniel Brolund(9314)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7857)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7406)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7328)
Grails in Action by Glen Smith Peter Ledbrook(7303)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7122)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5962)
Kotlin in Action by Dmitry Jemerov(4647)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3890)
Functional Programming in JavaScript by Mantyla Dan(3723)
Learning Java by Patrick Niemeyer & Daniel Leuck(2872)
Mastering Python for Finance by Weiming James Ma;(2840)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2839)
Windows APT Warfare by Sheng-Hao Ma(2625)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2605)
Mastering Java 9 by Dr. Edward Lavieri(2573)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2560)