Created
March 27, 2019 10:21
-
-
Save Aluriak/210d20b689b0800d2d9830a6c1f38422 to your computer and use it in GitHub Desktop.
Example of pandas/seaborn heatmap generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example of pandas/seaborn heatmap generation""" | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
def heatmap_using_seaborn(data): | |
import seaborn as sns; sns.set() | |
ax = sns.heatmap(data) | |
plt.show() | |
def heatmap_using_pandas(data): | |
import numpy as np ; np.random.seed(0) | |
plt.pcolor(data) | |
plt.yticks(np.arange(0.5, len(data.index), 1), data.index) | |
plt.xticks(np.arange(0.5, len(data.columns), 1), data.columns) | |
plt.show() | |
data = pd.DataFrame({ | |
'left': [0, 10, 20, 30, 33, 40, 0, 10], | |
'center': [100, 80, 60, 40, 34, 20, 10, 20], | |
'right': [0, 10, 20, 30, 33, 40, 90, 70], | |
}) | |
# pick one, the seaborn one is better, but needs seaborn package | |
heatmap_using_pandas(data) | |
heatmap_using_seaborn(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment