
How to Generate FiveThirtyEight Graphs in Python - mircealex
https://www.dataquest.io/blog/making-538-plots/
======
minimaxir
It's worth nothing as an interesting background note that FiveThirtyEight uses
ggplot2/R for their data visualization workflows instead of matplotlib/Python.
Specifically, they export ggplot2 visualizations as a PDF/SVG vector image
which then can be precisely annotated in Illustrator.

More info in this video: [https://channel9.msdn.com/Events/useR-international-
R-User-c...](https://channel9.msdn.com/Events/useR-international-R-User-
conference/useR2016/FiveThirtyEights-data-journalism-workflow-
with-R?ocid=player)

~~~
willium
This isn't strictly true. They use an internal tool built using Victory[1]

1:
[https://github.com/FormidableLabs/victory](https://github.com/FormidableLabs/victory)

------
amelius
The problem I have with most graph plotting libraries: the examples always
look great, but they tend to break down on real world data in unexpected ways.
Think of overlapping labels, inappropriately placed legends, inappropriately
chosen axis ranges, et cetera.

~~~
lottin
True, some details often require fine-tuning to get them perfectly right. Then
again, making plots is a bit of an art, so I'm okay with that.

------
wallabie
I didn't know that there was a fivethirtyeight style in matplotlib. Tres cool!

~~~
abhirag
Matplotlib also allows xkcd style plots [1] if that is something you fancy :)

[1] -- [http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-
matpl...](http://jakevdp.github.io/blog/2013/07/10/XKCD-plots-in-matplotlib/)

~~~
jonathanpoulter
The XKCD graphing is really easy to do, maybe FTE could be refined and
incorporated too

~~~
freehunter
I would abbreviate "FiveThirtyEight" as just 538. It's far clearer.

~~~
petemc_
That was the abbreviation used in TFA.

------
rflrob
For the attribution bar at the bottom of the figure, why not use the text()
kwarg xycoords="figure points" or "figure pixels", which both enforces the
semantic distinction between the axes (where the data goes) and the figure
(where other stuff goes), and avoids having to guess and check the
coordinates.

------
v3gas
Pretty cool, but I actually prefer the standard style in matplotlib.

~~~
bede
I agree – it's interesting how one is initially drawn to, yet eventually tires
of these sorts of plot styles. While Seaborn strikes a good balance, clear and
simple monochrome plots never go out of fashion. This is just as much the case
when building fancy interactive plots using Shiny/Plotly etc.

~~~
abhirag
Interesting, @bede @v3gas I would love to hear your thoughts on my plots --
[http://abhirag.in/articles/price_data_present.html](http://abhirag.in/articles/price_data_present.html)

Too fancy? Too plain? Kinda ok? Kinda new to matplotlib, so your feedback
would help :)

~~~
nekopa
Nice charts.

Just one idea, on your vegetable chart, you have onions as a red line and
tomatoes as yellow. I would swap them around, as I automatically associate
tomatoes with red.

~~~
abhirag
Valid point :) I'll change the order of colors in my palette.

------
yeukhon
Interesting article, and very helpful. Over the years whenever I need to
generate a graph I'd know I have to play around with axies.

Would be more interesting if someone could actuslly replicate the Irma one.
But I figure it probably is a plotting around the datapoint (similar idea like
a best fit line, but as a curve).

So my tl;dr for generating any interesting graph is a lot of coding... a lot
of playing with attributes and modeling.

------
JaniceLeblanc
I am not familiar with FiveThirtyEight but these graphs look quite nice.

------
megamindbrian
Or learn JavaScript and just use D3. It does this out of the box given the
dataset.

~~~
alanbernstein
D3 looks really nice, but half the time I try to use it for something that
doesn't closely match a Bostock example, I end up giving up and just coding it
myself with SVG primitives. I don't understand the motivation behind D3's
complex API.

~~~
dreamcompiler
D3 is a functional paradigm for graphics. From the D3 intro: "...styles,
attributes, and other properties can be specified as functions of data in D3,
not just simple constants."

This sounds trite, but it's enormously powerful and it's what makes D3 worth
learning.

------
catacombs
Why go through all this trouble? You can accomplish the same plot in less than
10 lines of code in R, which includes a 538 theme.

~~~
wodenokoto
I'd love to see those 10 lines!

~~~
minimaxir
I have a R/ggplot2 data visualization tutorial which gets a similar style in
about 10 lines:
[http://minimaxir.com/2017/08/ggplot2-web/](http://minimaxir.com/2017/08/ggplot2-web/)

~~~
mircealex
You're not adding a title, a subtitle, a signature bar. You're not bolding the
line at y = 0, you're using block-style legends instead of adding customized
labels. All these will require extra code.

Your example is potentially misleading in this discussion for anyone who won't
bother to go through that article you linked to.

I'm not saying you can't do the graphs in under 10 lines of code, I'm just
saying that your example totally misses the point.

~~~
minimaxir
The key word is "similar." (and yes I do add a titles/subtitle bar/caption)

~~~
mircealex
Apologies, I only examined the first couple of graphs after the first
"FiveThirtyEight" keyword, for which you don't have titles, subtitles etc.

The graphs on your article look really nice, but they are quite far from
resembling FTE's, IMO.

