Point (x,y) draws a single point at (x,y) Line (x1, y1, x2, y2) draws a line from the first (x, y) to the second (x, y) Rect(x, y, w, h) draws a rectangle. Computer images are composed of these and shape functions such as ellipse are about setting the coordinates. Indentation Levels how Python denotes code belonging to a function block. text ( xloc, yloc, rankStr, horizontalalignment = align, verticalalignment = 'center', color = clr, weight = 'bold' ) plt. get_height () / 2.0 #Center the text vertically in the bar ax1. 1st, 2nd, 3rd, etc) lastDigit = width % 10 # Note that 11, 12, and 13 are special cases if ( width = 11 ) or ( width = 12 ) or ( width = 13 ): suffix = 'th' else : suffix = suffixes rankStr = str ( width ) suffix if ( width < 5 ): # The bars aren't wide enough to print the ranking inside xloc = width 1 # Shift the text to the right side of the right edge clr = 'black' # Black against white background align = 'left' else : xloc = 0.98 * width # Shift the text to the left side of the right edge clr = 'white' # White on magenta align = 'right' yloc = rect. get_width ()) # Figure out what the last digit (width modulo 10) so we can add # the appropriate numerical suffix (e.g. title () 's' ) # Lastly, write in the ranking inside each bar to aid in interpretation for rect in rects : # Rectangle widths are already integer-valued but are floating # type, so it helps to remove the trailing decimal point and 0 by # converting width to int type width = int ( rect. set_xlabel ( 'Percentile Ranking Across ' str ( grade ) suffixes \ set_ylabel ( 'Test Scores' ) #Make list of numerical suffixes corresponding to position in a list # 0 1 2 3 4 5 6 7 8 9 suffixes = ax2. We want the labels centered on the ticks, so if # there is no meta info (like for pushups) then don't add the carriage return to # the string def withnew ( i, scr ): if testMeta != '' : return ' %s \n ' % scr else : return scr scoreLabels = scoreLabels = pylab. plot (,, 'grey', alpha = 0.25 ) # Build up the score labels for the right Y-axis by first appending a carriage # return to each string and then tacking on the appropriate meta information # (i.e., 'laps' vs 'seconds'). grid ( True, linestyle = '-', which = 'major', color = 'grey', alpha = 0.25 ) #Plot a solid vertical gridline to highlight the median position plt. set_major_locator ( MaxNLocator ( 11 )) xticks = pylab. text ( 50, - 0.5, 'Cohort Size: ' str ( cohortSize ), horizontalalignment = 'center', size = 'small' ) # Set the right-hand Y-axis ticks and labels and set X-axis tick marks at the # deciles ax2 = ax1. barh ( pos, rankings, align = 'center', height = 0.5, color = 'm' ) ax1. arange ( numTests ) 0.5 #Center bars on the Y-axis ticks rects = ax1. set_window_title ( 'Eldorado K-8 Fitness Chart' ) pos = np. subplots_adjust ( left = 0.115, right = 0.88 ) fig. uniform ( 0, 1, numTests ) * 100, 0 ) fig = plt. """ import numpy as np import matplotlib.pyplot as plt import pylab from matplotlib.patches import Polygon from matplotlib.ticker import MaxNLocator student = 'Johnny Doe' grade = 2 gender = 'boy' cohortSize = 62 #The number of other 2nd grade boys numTests = 5 testNames = testMeta = scores = rankings = np. To extract the plotting code for demo purposes, we'll just make up some data for little Johnny Doe. """ Thanks Josh Hemann for the example This examples comes from an application in which grade school gym teachers wanted to be able to show parents how their child did across a handful of fitness tests, and importantly, relative to how other children did.
0 Comments
Leave a Reply. |