Skip to content

Add 3 new styles with color schemes from Tableau [backport to 1.4.x] #3700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Move y offsets into a dictionary
Provides a more concise way of storing the offsets rather than a long string of if statements.
  • Loading branch information
rhiever committed Oct 23, 2014
commit 8ef868a6de1eec312a7149e11d771a512055a303
34 changes: 10 additions & 24 deletions examples/showcase/bachelors_degrees_by_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
'Architecture', 'Physical Sciences', 'Computer Science',
'Engineering']

y_offsets = {"Foreign Languages":0.5, "English":-0.5, "Communications\nand Journalism":0.75,
"Art and Performance":-0.25, "Agriculture":1.25, "Social Sciences and History":0.25,
"Business":-0.75, "Math and Statistics":0.75, "Architecture":-0.75,
"Computer Science":0.75, "Engineering":-0.25}

for rank, column in enumerate(majors):
# Plot each line separately with its own color, using the Tableau 20
# color set in order.
Expand All @@ -40,29 +45,10 @@

# Add a text label to the right end of every line. Most of the code below
# is adding specific offsets y position because some labels overlapped.
y_pos = gender_degree_data[column.replace("\n", " ")].values[-1] - 0.5
if column == "Foreign Languages":
y_pos += 0.5
elif column == "English":
y_pos -= 0.5
elif column == "Communications\nand Journalism":
y_pos += 0.75
elif column == "Art and Performance":
y_pos -= 0.25
elif column == "Agriculture":
y_pos += 1.25
elif column == "Social Sciences and History":
y_pos += 0.25
elif column == "Business":
y_pos -= 0.75
elif column == "Math and Statistics":
y_pos += 0.75
elif column == "Architecture":
y_pos -= 0.75
elif column == "Computer Science":
y_pos += 0.75
elif column == "Engineering":
y_pos -= 0.25
y_pos = gender_degree_data[column.replace("\n", " ")].values[-1] - 0.5

if column in y_offsets:
y_pos += y_offsets[column]

# Again, make sure that all labels are large enough to be easily read
# by the viewer.
Expand All @@ -77,7 +63,7 @@
# Note that if the title is descriptive enough, it is unnecessary to include
# axis labels; they are self-evident, in this plot's case.
plt.text(1995, 92,"Percentage of Bachelor's degrees conferred to women in the "
"U.S.A. by major (1970-2010)", fontsize=17, ha="center")
"U.S.A. by major (1970-2010)", fontsize=17, ha="center")

# Finally, save the figure as a PNG.
# You can also save it as a PDF, JPEG, etc.
Expand Down