Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to plot heatmap in python

import seaborn as sns
f,ax = plt.subplots(figsize=(20, 20))
sns.heatmap(df.corr(), annot = True, fmt= '.2f')
Comment

heatmap in python

correlation=df.corr()
sns.heatmap(correlation,cbar=True,square=True,fmt='.1f',annot=True,annot_kws={'size':8},cmap="Blues")
Comment

python heatmap

Plotly
https://youtu.be/RgRwsKjkJnU
Comment

python image heatmap

# Does this work for you?

# was gonna use numpy
import numpy as np

# Anyways, defining the function
def heatmap(data, row_labels, col_labels, ax=None,
            cbar_kw={}, cbarlabel="", **kwargs):
    
    # Create a figure if we do not have one
    if ax is None:
        fig, ax = plt.subplots()
    
    # Create a heatmap
    im = ax.imshow(data, **kwargs)
    
    # Create colorbar
    cbar = ax.figure.colorbar(im, ax=ax, **cbar_kw)
    cbar.ax.set_ylabel(cbarlabel, rotation=-90, va="bottom")
    
    # We want to show all ticks
    ax.set_xticks(np.arange(len(col_labels)))
    ax.set_yticks(np.arange(len(row_labels)))
    # We want to label ticks with the respective list entries
    ax.set_xticklabels(col_labels)
    ax.set_yticklabels(row_labels)
    
    # Let the horizontal axes labeling appear on top
    ax.tick_params(top=True, bottom=False,
                   labeltop=True, labelbottom=False)
    
    # Rotate the tick labels and set their alignment.
    plt.setp(ax.get_xticklabels(), rotation=-30, ha="right", rotation_mode="anchor")
    
    # Turn spines off and create white grid.
    for edge, spine in ax.spines.items():
        spine.set_visible(False)
    ax.set_xticks(np.arange(data.shape[1]+1)-.5, minor=True)
    ax.set_yticks(np.arange(data.shape[0]+1)-.5, minor=True)
    ax.grid(which="minor", color="w", linestyle='-', linewidth=1)
    ax.tick_params(which="minor", bottom=False, left=False)
    
    return im, cbar # return the image and colorbar
    
Comment

PREVIOUS NEXT
Code Example
Python :: django queryset count 
Python :: current url in djago 
Python :: pytest teardown method 
Python :: how to copy file from local to sftp using python 
Python :: delete occurrences of an element if it occurs more than n times python 
Python :: set environment variable flask app 
Python :: python string cut last n characters 
Python :: series.string.split expand 
Python :: selenium webdriver options python 
Python :: how to add values to a list in python 
Python :: delete row if contains certain text pandas 
Python :: to str python 
Python :: numpy random choice 
Python :: a string starts with an uppercase python 
Python :: logical operators pandas 
Python :: Tensor.expand_as 
Python :: python datetime greater than now 
Python :: blender show python version 
Python :: render() in django 
Python :: python png library 
Python :: concatenate string and int python 
Python :: python convert object to json 
Python :: how to take two space separated int in python 
Python :: how to eliminate duplicate values in list python 
Python :: python dictionary sort by value then alphabetically 
Python :: docker flask 
Python :: Could not find a version that satisfies the requirement ckeditor 
Python :: roc auc score plotting 
Python :: yticks matplotlib 
Python :: py2exe no console 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =