python


Bar Chart(height) not equal


i tried a bar chart with add a value labels from my csv file and its work but i got a problem why the height of the bar chart is not equal?
CSV file :
CPU_5_SEC;CPU_1_MIN;CPU_5_MIN;
27;17;16;
Code :
import numpy as np
import matplotlib.pyplot as plt
N = 3
men_std=(0,1,2)
data = np.loadtxt('show-process-cpu.csv',dtype=bytes, delimiter=';', usecols=(0,1,2))
utilization= data[1]
label = np.loadtxt('show-process-cpu.csv',dtype=bytes, delimiter=';', usecols=(0,1,2)).astype(str)
my_xticks = label[0]
ind = np.arange(N)
width = 0.40
rects = plt.bar(ind, utilization, width ,men_std,color='r',)
plt.title("Cpu Utilization\n ('%') ")
plt.xticks(ind,my_xticks)
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2,height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects)
plt.show()
Your ax.bar second argument needs to be an array of integers. I also removed men_std=(0,1,2) argument and definition, since this makes the bars to be plotted in different heights.
import numpy as np
import matplotlib.pyplot as plt
N = 3
data = np.loadtxt('show-process-cpu.csv',dtype=bytes, delimiter=';', usecols=(0,1,2))
my_xticks = data[0]
utilization = data[1]
utilization_int = [int(x) for x in utilization]
ind = np.arange(N)
width = 0.40
fig, ax = plt.subplots()
rects1 = ax.bar(ind, utilization_int, width,color='r',)
ax.set_title("Cpu Utilization\n ('%') ")
ax.set_xticks(ind)
ax.set_xticklabels(my_xticks)
def autolabel(rects):
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2,height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
plt.show()
now its worked, Thanks for taking the time to contribute an answer :)
this is my first time learning code with python, and now i got it that's why the output is like that.
thanks :)

Related Links

Flask return SUM into Jinja2 list
i tried this sql request on python but is not working
Passing command line arguments in python by pytest
Not using grid anywhere in class still gives error 'cannot use geometry manager pack inside . which already has slaves managed by grid' in tkinter
Minimax Alogrithm for TicTacToe [python]
Zero Crossings Rate
Recursive function with one argument that does something to each element
Storing and Graphing results of API queried via Python. [on hold]
While handling Exceptions, how to print any error statement that occurs? See below for more details
Having trouble getting my calculator app to print the result I want
Why am I getting this ValueError?
How to recognize single digit in string to insert leading zero?
How can I configure a test environment with Falcon
Computing the gradient for a custom TensorFlow op with py_func()
get all files in drive via REST API
Setting an image as a tkinter window background

Categories

HOME
json
jsf
dotnetrdf
xamarin.android
freepascal
drupal-7
ubuntu-16.04
decorator
codeblocks
structuremap
camera-calibration
simple-injector
future
mod-pagespeed
scaling
android-toolbar
tweets
countif
binutils
rhmap
hash-collision
pentaho-report-designer
bxslider
cell-array
pari
read-write
threshold
honeysql
passenger
ksoap
swagger-editor
parent
excel-interop
intersystems-ensemble
median
estimation
rdw
amazon-machine-learning
mouseclick-event
tiddlywiki
ticker
mcrypt
etherpad
httplib2
unity3d-editor
emgu
iostat
icefaces
vst
spark-cassandra-connector
spring-lemon
remoteapp
approval-tests
unity5.3
uialertview
vine
httpie
adodb
musl
obfuscar
and-operator
fragment-tab-host
em
firebug-lite
adaptive-compression
aquafold
phpdocx
android-looper
kraken.js
voldemort
reserved-words
roxygen
facebook-chat
java.util.date
nsmatrix
asp.net-mvc-scaffolding
multiple-conditions
resgen
objcmongodb
transitive-closure-table
dropdownlistfor
attachevent
pitch
web-safe-fonts
cadisplaylink
getusermedia
shim
expression-evaluation
parameterization
makefile-project
throttling
scraperwiki
datamember
associative
pci-bus
inline-if
usergroups

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App