1

I want to change the color of the bars in this code all the bars are of same color and I want to show different values on top of each bar which are stored in maxtweet,p,n variables.

x=[]
x.append(max_tweets)
x.append(p)
x.append(n)
label=('tweets','positivity','nagitivity')
label_pos=np.arange(len(label))
plt.bar(label_pos,x,align='center',color='k')
plt.xticks(label_pos,label)
plt.xlabel('People Behaviour and Emotions')
plt.title('Sentiment Analysis')
plt.show()

1 Answer 1

3
import matplotlib.pylab as plt
import numpy as np
max_tweets = 19
p = 20
n = 30

datas = [{'label':'tweets', 'color': 'r', 'height': max_tweets},
    {'label':'positivity', 'color': 'g', 'height': p},
    {'label':'nagitivity', 'color': 'b', 'height': n}]

i = 0
for data in datas:
    plt.bar(i, data['height'],align='center',color=data['color'])
    i += 1

labels = [data['label'] for data in datas]
pos = [i for i in range(len(datas)) ]
plt.xticks(pos, labels)
plt.xlabel('People Behaviour and Emotions')
plt.title('Sentiment Analysis')
plt.show()

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.