


In our second example, we will make a scatterplot. We will not deal with all of these but we have dealt with the following This has been discussed in another post but a summary of the components are below. In addition, Altair follows the grammar of graphics for creating plots. We will learn more about saving plots later. The three dots in the upper right provide options for saving or editing the plot. In this case we are looking at job type and prestige. encode() function contains the information for the variables that will be assigned to the x and y axes. Line 2 uses several functions together to make the bar graph.Chart(df) loads the data for the plot.mark_bar() assigns the geomtric shape for the plot which in this case is bars.The code is below followed by the visualization. Our first visualization is a simple bar graph. You can see in the imagine above what variables are available. head() function to take a look at the dataset. Next, we load the “Duncan” dataset as the object “df”. In the code above, we load pandas and import “data” from the “pydataset” library. Simple replace “altair vega_datasets” with “pydataset.” Below is the initial code followed by the output import pandas as pd If you do not have pydataset install on your ocmputer you can use the code listed above to install it. We are going to make some simple visualizations using the “Duncan” dataset from the pydataset library using Altair. Which one of the lines above you use will depend on the type of Python installation you have. If Altair is not already install on your computer you can do so with the following code pip install altair vega_datasetsĬonda install -c conda-forge altair vega_datasets Altair solves this problem as Python is often seen as easier to work with compared to javascript. D3.js works but is cumbersome to work with for the avaerage non-coder. In the past, making interactions for website was often tught using a jacascript library such as d3.js. The interactions can take place inside jupyter or they can be exported and loaded onto websites as we shall see.
