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(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8300)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7781)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6849)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6584)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6454)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6417)
Kotlin in Action by Dmitry Jemerov(5065)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4317)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(4009)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3801)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3745)
The Ultimate iOS Interview Playbook by Avi Tsadok(3719)
