Last active
May 28, 2017 13:57
-
-
Save afrendeiro/54f9da88569e5953eb3e48d6652aec97 to your computer and use it in GitHub Desktop.
Mixing vector and rasterized elements in svg produced with matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set_style("white") | |
fig, axis = plt.subplots(1) | |
# all genes | |
axis.scatter( | |
np.arange(0, 8, 8./10000) + np.random.normal(0, 0.1, size=10000), | |
np.arange(0, 8, 8./10000) + np.random.normal(0, 0.1, size=10000), | |
color="grey", s=3, alpha=0.3, | |
rasterized=True) # Here's the magic: these points will be rasterized in the svg while everything else will be vectorized | |
# diff genes | |
axis.scatter( | |
np.arange(0, 8, 8./100) + -np.absolute(np.random.normal(0, 0.3, size=100)), | |
np.arange(0, 8, 8./100) + np.absolute(np.random.normal(0, 0.3, size=100)), | |
color="red", s=8, alpha=0.75) | |
axis.scatter( | |
np.arange(0, 8, 8./100) + np.absolute(np.random.normal(0, 0.3, size=100)), | |
np.arange(0, 8, 8./100) + -np.absolute(np.random.normal(0, 0.3, size=100)), | |
color="blue", s=8, alpha=0.75) | |
sns.despine(fig) | |
fig.savefig("example.svg", bbox_inches="tight") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment