Edinburgh-Genome-Foundry / DnaFeaturesViewer

:eye: Python library to plot DNA sequence features (e.g. from Genbank files)
https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/
MIT License
584 stars 90 forks source link

FigureCanvasQTCairo #31

Open andersonbrito opened 4 years ago

andersonbrito commented 4 years ago

Hi,

Thank you for creating this useful resource.

I'm trying to run the example shown in "Reading the features from a GenBank or GFF file", using the code below:

from dna_features_viewer import BiopythonTranslator

annotation = BiopythonTranslator().translate_record("example.gb")
ax, _ = annotation.plot(figure_width=10, strand_in_label_threshold=7)

... but I'm getting this error. Could you point me to a solution? I couldn't find it among the existing 'Issues'. Thank you

    ax, _ = annotation.plot(figure_width=10, strand_in_label_threshold=7)
  File "/anaconda3/lib/python3.7/site-packages/dna_features_viewer/GraphicRecord/MatplotlibPlottableMixin.py", line 445, in plot
    renderer = ax.figure.canvas.get_renderer()
AttributeError: 'FigureCanvasQTCairo' object has no attribute 'get_renderer'
Zulko commented 4 years ago

What is your matplotlib version?

import matplotlib
print (matplotlib.__version__)
andersonbrito commented 4 years ago

I'm using the version 3.1.3

Zulko commented 4 years ago

Hmmm, same version I have on my machine, and I don't get any error.

Try adding this at the top of your script:

import matplotlib
matplotlib.use('agg')
andersonbrito commented 4 years ago

Thank you, @Zulko.

I tried now using matplotlib.use("Agg"), the error is gone. However, I've been only able to see the results as an exported PNG/PDF file.

from dna_features_viewer import BiopythonTranslator
ax, _ = annotation.plot()
annotation.plot_legend(ax=ax)
ax.figure.tight_layout()
ax.figure.savefig(path + "custom_bopython_translator.pdf")

Which command one can use to see the plot on XQuartz? Is it possible with the Agg renderer?