Matplotlib Styles: FiveThirtyEight
Case Study: Takeaways
by
Dataquest Labs, Inc. - All rights reserved © 2023
Syntax
Concepts
Resources
Takeaways by Dataquest Labs, Inc. - All rights reserved © 2023
Using
a speci
fi
c Matplotlib style:
import matplotlib.style as style
style.use('fivethirtyeight')
plt.plot([1, 2, 3], [5, 2, 7])
plt.show()
•
Checking Matplotlib's styles:
print(style.available)
•
Moving the x-coordinate of the left sides of the bars by using the left parameter:
ax.barh(left)
•
Adding a signature bar with name and data source:
ax.text(x, y, 'Creator' + ' ' * 90 + 'Source',
color,
backgroundcolor)
•
Matplotlib's
pre-de
fi
ned styles change the default visual properties of graphs.
•
We must call the
style.use()
function before we create the graph.
•
Once
we use a certain style, all subsequent graphs will inherit that style.
•
To return to the default settings, use
style.use('default')
.
•
If you
want to switch between di
ff
erent styles, use style.use('default') between each change —
some of the styles can interfere with one another.
•
Blog Post: FiveThirtyEight Graphs Tutorial
•