Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Another example: using a colorbar to show bar height

import matplotlib.pyplot as plt
from matplotlib.cm import ScalarMappable

data_x = [0,1,2,3]
data_hight = [60,60,80,100]

data_hight_normalized = [x / max(data_hight) for x in data_hight]

fig, ax = plt.subplots(figsize=(15, 4))

my_cmap = plt.cm.get_cmap('GnBu')
colors = my_cmap(data_hight_normalized)

rects = ax.bar(data_x, data_hight, color=colors)

sm = ScalarMappable(cmap=my_cmap, norm=plt.Normalize(0,max(data_hight)))

sm.set_array([])

cbar = plt.colorbar(sm)
cbar.set_label('Color', rotation=270,labelpad=25)

plt.xticks(data_x)    
plt.ylabel("Y")

plt.title('How to plot a bar chart with a colorbar with matplotlib ?')

plt.savefig("bar_chart_with_colorbar_03.png", bbox_inches='tight')

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: python scrapy 
Python :: find mising number in O(n) 
Python :: How to get the positions where values of two columns match? 
Python :: Insert Multiple Images to Excel with Python 
Python :: Qt convert image to base64 
Python :: python load array 
Python :: python web app with redis github 
Python :: add a third dimension matrix dataset python 
Python :: formula e xiaomi 
Python :: pylint no name in module opencv 
Python :: python program to get equally distributed number from given range 
Python :: Logistic Regression with a Neural Network mindset python example 
Python :: Increase "bar width" "px.bar" 
Python :: 2600/6 
Python :: url namespaces for django rest router urls 
Python :: get attribute of timestamp python 
Python :: boolean indexing datetime object | converting string to datetime object 
Python :: python fibbonacci 
Python :: python mypy cast 
Python :: matplotlib FiveThirtyEight creating a signature 
Python :: polycarp and coins codeforces solution 
Python :: priting matrix using np truncating the output 
Python :: hebrew range 
Python :: check if timestamp is NaT 
Python :: "opencv write video" 
Python :: install python3 yum centOS redhat 
Python :: how to run 2 async function forever 
Python :: split string into words and separators 
Python :: use dict to replace missing values pandas 
Python :: how to join bot into voice channel python 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =