Home > Software engineering >  Adding symbols to some variables in matplotlib bar plots
Adding symbols to some variables in matplotlib bar plots

Time:08-02

I would like to add stars to certain variables in a matplotlib.pyplot bar plot.

import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
ind = np.arange(N) # the x locations for the groups
width = 0.35
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.bar(ind, menMeans, width, color='r')
ax.bar(ind, womenMeans, width,bottom=menMeans, color='b')
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
ax.set_yticks(np.arange(0, 81, 10))
ax.legend(labels=['Men', 'Women'])
plt.show()

Supose I wanted to add stars *** to the top of the bars at G1 and G3. How could I do this? enter image description here

CodePudding user response:

You could do it by placing the *** with enter image description here

  • Related