Skip to content

Instantly share code, notes, and snippets.

@afrendeiro
Last active May 28, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afrendeiro/54f9da88569e5953eb3e48d6652aec97 to your computer and use it in GitHub Desktop.
Save afrendeiro/54f9da88569e5953eb3e48d6652aec97 to your computer and use it in GitHub Desktop.
Mixing vector and rasterized elements in svg produced with matplotlib
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