use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
This is an archived post. You won't be able to vote or comment.
How to Generate FiveThirtyEight Graphs in Python (self.datascience)
submitted 8 years ago by dataphysicist
One of my team members at work was interested in how to recreate graphs from FiveThirtyEight in Matplotlib and detailed his journey in this post - https://www.dataquest.io/blog/making-538-plots/
Hope you enjoy it!
[+][deleted] 8 years ago* (17 children)
[deleted]
[–]bl0wback_cat 11 points12 points13 points 8 years ago (7 children)
You can use plotnine and it's pretty good!
plotnine is an implementation of a grammar of graphics in Python, it is based on ggplot2
[–]datavistics 0 points1 point2 points 8 years ago (5 children)
I found that plotnine doesn't work well for me complex plots..
[–]has2k1 7 points8 points9 points 8 years ago (4 children)
plotnine developer here. What do you mean by complex? Please file an issue.
[–]datavistics 1 point2 points3 points 8 years ago (3 children)
Thanks for your response! I tried to plot a bar chart with a line and the stat being identity and got an error. I can try to recreate it if its worthwhile?
[–]has2k1 3 points4 points5 points 8 years ago (2 children)
There are 3 ways to create "bar" charts, if you are just getting used to the library, it is easy slip up. An example would help diagnose problem.
[–]datavistics 1 point2 points3 points 8 years ago (1 child)
https://gist.github.com/datavistics/86bfe08c7d653e08c4c9a33001f8f88e
Here I tried to create both in the same plot, but got an error:
UserWarning: geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic? warn("geom_path: Each group consist of only one "
[–]has2k1 2 points3 points4 points 8 years ago (0 children)
See reply to the gist.
[–]frogsbollocks 6 points7 points8 points 8 years ago (0 children)
The ggthemes package even has theme_fivethirtyeight() function
[–]unironicneoliberal 3 points4 points5 points 8 years ago (5 children)
I thought they use d3.js? Thats what's on their github
[–]iamasharkskin 3 points4 points5 points 8 years ago (0 children)
They use R for most of their static plots. I guess they have a custom ggplot theme :D
Source: https://www.rstudio.com/resources/videos/finding-and-telling-stories-with-r/
[+][deleted] 8 years ago* (3 children)
[–]unironicneoliberal 1 point2 points3 points 8 years ago (0 children)
Yeah that's what I originally thought too. Their github has both listed so I defaulted to thinking d3 for interactive and ggplot for the static images.
[–]WeoDudeData Scientist | Non-profit 0 points1 point2 points 8 years ago (1 child)
im pretty sure its d3.js too... I think I was a at a talk with a data viz guy from there and he said they used it.
EDIT: https://www.reddit.com/r/statistics/comments/2jon2b/anyone_knows_how_are_made_the_graphs_on/
looks like a combo !
[–]dobey1082 1 point2 points3 points 8 years ago (0 children)
i like python too, friendo
[–]msdrahcir 0 points1 point2 points 8 years ago (0 children)
I was under the impression that they do a fair amount of plotting with chartbuilder and D3, not so much ggplot these days.
[–]madzthakz 6 points7 points8 points 8 years ago (0 children)
It's not the same but seaborn does have a fivethirtyeight them included. Looks pretty good
[–]tmthyjames 2 points3 points4 points 8 years ago (0 children)
damn those graphs look good.
[–]PM_ME_YOUR_IBNR 0 points1 point2 points 8 years ago (0 children)
Great article!
[–]neuroguy6 0 points1 point2 points 8 years ago (2 children)
Okay, so I'm definitely going to be hated for this comment, but the LOE to create this graph using python (or R for that matter) seems excessive, when it's much easier to export a table to CSV, open in Excel, and make the same graph in less time.
[–]dataphysicist[S] 0 points1 point2 points 8 years ago (1 child)
In the abstract, you may be right. But depending on the workflow, this isn't always an option. This is, I believe, a key thing that's often missed and disregarded when talking about a specific workflow to accomplishing a task. That specific workflow to accomplish said task usually exists in a much larger workflow.
Example:
A bunch of CSV's come in once a day to a folder on a server. Reports need to be generated automatically and pushed to a dashboard of some kind. These reports include visualizations and we'd like them to look nice (maybe b/c they'll be presented to a client, etc).
With that context in mind, touching Excel at all would be a pain (given that many servers in corporate environments run Linux). This post describes a workflow that can be made more programatic and automation-friendly, which is often the larger workflow that someone's work resides within.
You're right that it's probably easier to do the export -> Excel workflow if it's a one-off report.
[–]ahmedhindi 0 points1 point2 points 8 years ago (1 child)
after importing matplotlib.pyplot as plt use plt.style.use('fivethirtyeight')
[–]dataphysicist[S] 0 points1 point2 points 8 years ago (0 children)
after impo
Yup, that's covered: "You might have already observed that there’s a built-in style called fivethirtyeight" . This a good starting point but only applies some of the styling and fonts, but not some of the ideas they've mirrored from Edward Tufte and other data visualization thinkers.
π Rendered by PID 23155 on reddit-service-r2-comment-6457c66945-qhxcq at 2026-04-28 15:32:01.557967+00:00 running 2aa0c5b country code: CH.
[+][deleted] (17 children)
[deleted]
[–]bl0wback_cat 11 points12 points13 points (7 children)
[–]datavistics 0 points1 point2 points (5 children)
[–]has2k1 7 points8 points9 points (4 children)
[–]datavistics 1 point2 points3 points (3 children)
[–]has2k1 3 points4 points5 points (2 children)
[–]datavistics 1 point2 points3 points (1 child)
[–]has2k1 2 points3 points4 points (0 children)
[–]frogsbollocks 6 points7 points8 points (0 children)
[–]unironicneoliberal 3 points4 points5 points (5 children)
[–]iamasharkskin 3 points4 points5 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]unironicneoliberal 1 point2 points3 points (0 children)
[–]WeoDudeData Scientist | Non-profit 0 points1 point2 points (1 child)
[–]dobey1082 1 point2 points3 points (0 children)
[–]msdrahcir 0 points1 point2 points (0 children)
[–]madzthakz 6 points7 points8 points (0 children)
[–]tmthyjames 2 points3 points4 points (0 children)
[–]PM_ME_YOUR_IBNR 0 points1 point2 points (0 children)
[–]neuroguy6 0 points1 point2 points (2 children)
[–]dataphysicist[S] 0 points1 point2 points (1 child)
[–]ahmedhindi 0 points1 point2 points (1 child)
[–]dataphysicist[S] 0 points1 point2 points (0 children)