Mis a jour le 2017-09-24, 21:34

Barplot

Barplot :
Exemple complet de barplot : pyplot.bar(range(5), [1, 3, 3, 5, 4], width = 0.6, color = 'yellow', edgecolor = 'blue', linewidth = 2, yerr = [0.5, 1, 2, 1, 2], ecolor = 'magenta', capsize = 10) pyplot.xticks([x + 0.6 / 2 for x in range(5)], ['A', 'B', 'C', 'D', 'E'], rotation = 45)
Exemple de barplot avec 2 séries de données : barWidth = 0.4 y1 = [1, 2, 4, 3] y2 = [3, 4, 4, 3] r1 = range(len(y1)) r2 = [x + barWidth for x in r1] pyplot.bar(r1, y1, width = barWidth, color = ['yellow' for i in y1], edgecolor = ['blue' for i in y1], linewidth = 2) pyplot.bar(r2, y2, width = barWidth, color = ['pink' for i in y1], edgecolor = ['green' for i in y1], linewidth = 4) pyplot.xticks([r + barWidth for r in range(len(y1))], ['A', 'B', 'C', 'D'])
Exemple de barplot avec 2 séries superposées : barWidth = 0.8 y1 = [1, 2, 4, 3] y2 = [3, 4, 4, 3] r = range(len(y1)) pyplot.bar(r, y1, width = barWidth, color = ['yellow' for i in y1], edgecolor = ['blue' for i in y1], linestyle = 'solid', hatch ='/', linewidth = 3) pyplot.bar(r, y2, width = barWidth, bottom = y1, color = ['pink' for i in y1], edgecolor = ['green' for i in y1], linestyle = 'dotted', hatch = 'o', linewidth = 3) pyplot.xticks([r + barWidth / 2 for r in range(len(y1))], ['A', 'B', 'C', 'D'])
Barplot horizontal : barWidth = 0.8 y1 = [1, 2, 4, 3] y2 = [3, 4, 4, 3] r = range(len(y1)) pyplot.barh(r, y1, height = barWidth, color = ['yellow' for i in y1], edgecolor = ['blue' for i in y1], linestyle = 'solid', hatch ='/', linewidth = 3) pyplot.barh(r, y2, height = barWidth, left = y1, color = ['pink' for i in y1], edgecolor = ['green' for i in y1], linestyle = 'dotted', hatch = 'o', linewidth = 3) pyplot.yticks([r + barWidth / 2 for r in range(len(y1))], ['A', 'B', 'C', 'D'])
Dans un barplot, pour supprimer les ticks sur l'axe des x (tout en conservant les labels) : faire pyplot.gca().axes.xaxis.set_ticks_position('none')

Copyright python-simple.com
programmer en python, tutoriel python, graphes en python, Aymeric Duclert