Getting Started¶
The vizta package makes it easy to use a consistent theme in our data visualizations. Additionally, it saves us time that would have been spent tweaking themes manually. Currently, vizta only supports matplotlib.
Installation¶
vizta is easily installed with pip:
pip install vizta
Alternatively, the development version can be installed with pip:
pip install git+https://github.com/TalusBio/vizta.git
You will also need to install any fonts used by your theme.
For the talusbio
theme, this is "Host Grotesk", which on a Mac can easily be installed with Homebrew:
brew install --cask font-host-grotesk
Usage¶
Theme your matplotlib plots for Talus Bio¶
Vizta let's us easily set our theme using vizta.mpl.set_theme()
, which behaves similarly to seaborn.set_theme()
.
First, we'll create a plot with some random data without a theme:
import numpy as np
import matplotlib.pyplot as plt
def make_plot():
"""Create a plot with random data"""
rng = np.random.default_rng(42) # To generate random number
plt.figure()
xdata = np.arange(100) / 100
plt.plot(xdata, xdata + rng.random(100), label="Series 1")
plt.plot(xdata, xdata + rng.random(100) + 0.5, label="Series 2")
plt.legend()
plt.xlabel("My x-axis label")
plt.ylabel("My y-axis label")
plt.tight_layout()
plt.show()
make_plot()
Now we can easily change such a plot to be Talus Bio themed:
import vizta # First import vizta
vizta.mpl.set_theme() # Set the theme
make_plot() # Then make the plot again
We can also change the plotting context for different types of presentations. This adjusts the font sizes and line thickness to be appropriate for the venue. See the seaborn documentation for more details.
vizta.mpl.set_theme(context="talk") # Set the theme for a talk
make_plot() # Then make the plot again
Retrieve the colors in the color palette¶
When vizta is imported, it adds our color palettes to those provided by seaborn.
To retrieve the Talus Bio color palette, use seaborn.color_palette()
.
Note that we currently only use 4 colors, although I would advise sticking with only 2.
import seaborn as sns
import vizta
sns.color_palette("talusbio")
Tips for Publication-Ready Figures¶
Read "Fundamentals of Data Visualization" by Claus Wilke. It is available for free online and offers sound advice for creating clear and appealing data viasualizations.
Create figures that are exactly the size that you want in your slide, poster, or paper. With matplotlib, you can specify the size of your figure in inches using the
figsize
argument:
import vizta
vizta.mpl.set_theme()
# Create a figure that is 6 in wide and 3 in tall, with 2 panels:
fig, axs = plt.subplots(1, 2, figsize=(6, 3))
plt.tight_layout()
axs[0].text(0.5, 0.5, "Left", ha="center")
axs[1].text(0.5, 0.5, "Right", ha="center")
plt.show()
- Bump up the resolution using the
dpi
argument:
plt.savefig("my-figure.png", dpi=72) # Good for web
plt.savefig("my-figure.png", dpi=300) # Good for print
<Figure size 640x480 with 0 Axes>
That's it. Have an issue? File it here: https://github.com/TalusBio/vizta/issues