Open In App

Python Altair – Scatter Plot

In this article, we will learn a Simple Scatter plot with Altair using python. Altair is one of the latest interactive data visualizations library in python. Altair is based on vega and vegalite– A grammar of interactive graphics.  Here we will import the Altair library for using it. And then we will load the Seattle weather data from vega_dataset.

Step-by-step Approach: 




# import required modules
import altair as alt
from vega_datasets import data




# assign dataset
seattle_weather = data.seattle_weather()




# display dataset
seattle_weather.head(5)

Output:








# depict scatter plot
alt.Chart(seattle_weather).mark_point().encode(
    x='temp_max',
    y='temp_min'
)

Output:

Below is the complete program based on the above approach:




# import required modules
import altair as alt
from vega_datasets import data
 
 
# assign dataset
seattle_weather = data.seattle_weather()
 
# display dataset
seattle_weather.head(5)
 
# depict scatter plot
alt.Chart(seattle_weather).mark_point().encode(
    x='temp_max',
    y='temp_min'
)

Output: 

 


Article Tags :