Created
December 14, 2015 12:42
-
-
Save anonymous/c8f61293827788cf55af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create string variable for Year | |
r['new_year'] = r.Year.astype('str') | |
#set colors for different plot type | |
colors1=sns.color_palette('husl', 8) #number represents how many things being plotted | |
#create plot in a different way so can enable markers specific to each MACOM | |
#can mess with the height and width using the figsize= | |
fig, ax = plt.subplots(figsize=(8, 4)) | |
#call in each variable to be plotted and specify the marker to use | |
#had to google what markers are available in matplotlib | |
ax.plot(r.new_year, r.ARMY, marker='o', linewidth=2,label='Army', color=colors1[0]) | |
ax.plot(r.new_year, r.MEDCOM, marker='v', linewidth=2,label='MEDCOM', color=colors1[1]) | |
ax.plot(r.new_year, r.TRADOC, marker='H', linewidth=2,label='TRADOC', color=colors1[2]) | |
ax.plot(r.new_year, r.USAREUR, marker='^', linewidth=2,label='USAREUR', color=colors1[3]) | |
ax.plot(r.new_year, r.FORSCOM, marker='8', linewidth=2,label='FORSCOM', color=colors1[4]) | |
ax.plot(r.new_year, r.USARPAC, marker='s', linewidth=2,label='USARPAC', color=colors1[5]) | |
ax.plot(r.new_year, r.USASOC, marker='s', linewidth=2,label='USASOC', color=colors1[6]) | |
ax.plot(r.new_year, r.EUSA, marker='D', linewidth=2,label='EUSA', color=colors1[7]) | |
ax.legend() | |
#add commas to y axis | |
ax.get_yaxis().set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ','))) | |
#label axes, move legend to outside plot, despine | |
ax.set_ylabel('Injury Rate per 1,000 Person Years') | |
ax.set_xlabel('Year') | |
ax.legend(bbox_to_anchor=(1.33, .9)) | |
sns.despine() | |
#save as a figure | |
fig.savefig('Figure1_Marker.png') | |
#for some reason the whole plot isn't being saved? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment