mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-04-22 10:28:02 +00:00
25 lines
545 B
Python
25 lines
545 B
Python
"""
|
|
Simple Heatmap
|
|
--------------
|
|
This example shows a simple heatmap for showing gridded data.
|
|
"""
|
|
# category: simple charts
|
|
import altair as alt
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
# Compute x^2 + y^2 across a 2D grid
|
|
x, y = np.meshgrid(range(-5, 5), range(-5, 5))
|
|
z = x ** 2 + y ** 2
|
|
|
|
# Convert this grid to columnar data expected by Altair
|
|
source = pd.DataFrame({'x': x.ravel(),
|
|
'y': y.ravel(),
|
|
'z': z.ravel()})
|
|
|
|
alt.Chart(source).mark_rect().encode(
|
|
x='x:O',
|
|
y='y:O',
|
|
color='z:Q'
|
|
)
|