theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
414 stars 102 forks source link

figure cannot be saved as pdf, using png instead. #279

Closed MichaelPeibo closed 4 years ago

MichaelPeibo commented 4 years ago

...

scv.pl.velocity_embedding_stream(cdata,basis='umap',legend_loc='right margin',fontsize=20,figsize=(8,8),
                                 title='RNA Velocity Stream',smooth=.5, min_mass=1,vkey='dynamical_velocity',
                                 color = "cluster",
                                save='test.pdf',
                                )

figure cannot be saved as pdf, using png instead. saving figure to file ./figures/scvelo_test.pdf.png

Versions:

Running scvelo 0.2.2 (python 3.7.3) on 2020-09-12 18:35.

VolkerBergen commented 4 years ago

This is a matplotlib bug, which is caught by scvelo to then save the fig as png instead of pdf. The former works, b/c it saves it as an image, while the latter sometimes cannot handle saving thousands of stream lines in vectorized form.

MichaelPeibo commented 4 years ago

@VolkerBergen thanks for clarification! Any solution toscv.pl.velocity_embedding_stream so that pdf image can be an option of output?

VolkerBergen commented 4 years ago

You could try running %matplotlib inline right at the start of your notebook (or trying different backends).

MichaelPeibo commented 4 years ago

Here is my first lines of code:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
%matplotlib inline
import scvelo as scv
scv.logging.print_version()
import numpy as np
import pandas as pd
import scanpy as sc
import loompy
print(loompy.__version__)
import os
import matplotlib
import matplotlib.pyplot as plt
pd.options.display.max_columns = None
from matplotlib import rcParams

scv.settings.verbosity = 3  # show errors(0), warnings(1), info(2), hints(3)
scv.settings.set_figure_params('scvelo',dpi_save=300)  # for beautified visualization
plt.rcParams['pdf.fonttype'] = 'truetype'

Unfortunately, it did not work. The magic thing is, this bug just suddenly happened. I have no idea...

gokceneraslan commented 3 years ago

Is there an upstream (i.e. mpl) GitHub issue for this?

chansigit commented 2 years ago

the same issue, not resolved.

an alternative is to save in svg format

MichaelPeibo commented 2 years ago

the same issue, not resolved.

an alternative is to save in svg format

Hi, I forget how I overcome this issue, but my suggestion is to update correlated packages.

DawnEve commented 2 years ago

In my test, when the fig is too wide, it may output png, rather than pdf. Other samples output pdf on the same machine and same code and packages.

Roger-GOAT commented 1 year ago

@MichaelPeibo hi, could you remember which packages should be updated? thanks!

MichaelPeibo commented 1 year ago

@MichaelPeibo hi, could you remember which packages should be updated? thanks!

Hi @Roger-GOAT, I don't really remember which packages I updated. Some of them are dependent on each other, so try to make all main packages up to date. Best of luck!

YaoXueming commented 1 year ago

please refer to issue #85, you may save it as svg and then convert it to pdf.