Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

add label to colorbar

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
m = ax.imshow(X)
cbar = plt.colorbar(m)
cbar.set_label('X+Y')
plt.show()
Comment

add label to colorbar


import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap

#discrete color scheme
cMap = ListedColormap(['white', 'green', 'blue','red'])

#data
np.random.seed(42)
data = np.random.rand(4, 4)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=cMap)

#legend
cbar = plt.colorbar(heatmap)

cbar.ax.get_yaxis().set_ticks([])
for j, lab in enumerate(['$0$','$1$','$2$','$>3$']):
    cbar.ax.text(.5, (2 * j + 1) / 8.0, lab, ha='center', va='center')
cbar.ax.get_yaxis().labelpad = 15
cbar.ax.set_ylabel('# of contacts', rotation=270)


# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)
ax.invert_yaxis()

#labels
column_labels = list('ABCD')
row_labels = list('WXYZ')
ax.set_xticklabels(column_labels, minor=False)
ax.set_yticklabels(row_labels, minor=False)

plt.show()

Comment

PREVIOUS NEXT
Code Example
Python :: python telegram 
Python :: how to make code to do something for curtain number of seconds python 
Python :: Does np.tile Work in More Than 2 Dimensions 
Python :: pandas series add word to every item in series 
Python :: python save image pytelegrambotapi 
Python :: python select columns names from dataframe 
Python :: Python Tuples Tuples allow duplicate values 
Python :: pdf to excel conversion using python 
Python :: how to see truncated values in jupyter notebook 
Python :: python eliptic curve matplotlib 
Python :: How To Let Your Main Window Appear after succesful login in Tkinter 
Python :: series floor 
Python :: Convert Int to String Using str() function 
Python :: how to add items to tuple in python 
Python :: gtts python 
Python :: python create valid filename from string 
Python :: Python Import all names 
Python :: how to get maximum value of number in python 
Python :: django get current user in form 
Python :: #Check if list1 contains all elements of list2 using all() 
Python :: extract column of n array 
Python :: how to capitalize words in python 
Python :: print index and value on each iteration of the for loop in Python 
Python :: get sum of column before a date python 
Python :: alphabeticallly 
Python :: unique file name in django 
Python :: check even or odd in single line 
Python :: powershell bulk rename and add extra string to filename 
Python :: how to get wikipedia page link in python 
Python :: how to use histogram in python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =