Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd51da8

Browse files
tacaswellmdboom
authored andcommitted
made example clearer
- use OO interface to set tick labels rather than pyplot - explicitly set ax2.ylim, rather than relying on auto-scale magic
1 parent ff62378 commit cd51da8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

examples/pylab_examples/barchart_demo2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ def withnew(i, scr):
6565

6666
scoreLabels = [withnew(i, scr) for i, scr in enumerate(scores)]
6767
scoreLabels = [i+j for i, j in zip(scoreLabels, testMeta)]
68-
pylab.yticks(pos, scoreLabels)
68+
# set the tick locations
69+
ax2.set_yticks(pos)
70+
# set the tick labels
71+
ax2.set_yticklabels(scoreLabels)
72+
# make sure that the limits are set equally on both yaxis so the ticks line up
73+
ax2.set_ylim(ax1.get_ylim())
74+
75+
6976
ax2.set_ylabel('Test Scores')
7077
#Make list of numerical suffixes corresponding to position in a list
7178
# 0 1 2 3 4 5 6 7 8 9
7279
suffixes = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
7380
ax2.set_xlabel('Percentile Ranking Across ' + str(grade) + suffixes[grade]
7481
+ ' Grade ' + gender.title() + 's')
7582

76-
7783
# Lastly, write in the ranking inside each bar to aid in interpretation
7884
for rect in rects:
7985
# Rectangle widths are already integer-valued but are floating

0 commit comments

Comments
 (0)