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

bug in graphic_record.plot with x_lim? #26

Closed dmnfarrell closed 4 years ago

dmnfarrell commented 4 years ago

Hi. I'm trying to plot a selected region of features in a SeqRecord over a specific range. I assume this is the purpose of the x_lim argument? However if I supply a range to this as a tuple I still get the features over the entire range shown which seems to distort the x axis range.

Plotting all the features works fine:

graphic_record = BiopythonTranslator().translate_record(rec)
ax, _ = graphic_record.plot(figure_width=16, strand_in_label_threshold=7)

Gives this:

download

But using x_lim:

ax, _ = graphic_record.plot(figure_width=16, strand_in_label_threshold=7, x_lim=(5000,15000))

Produces this plot:

download (1)

Zulko commented 4 years ago

It's not a bug but I should clarify the documentation. The x_lim factor is not meant to be used to crop the plot, only to increase the range of the x axis beyond the length of the sequence, for instance to make sure that different plots are on the same scale.

To crop the plot, use .crop method and it should work fine:

cropped_record = graphic_record.crop((5000,15000))
ax, _ = cropped_record.plot(figure_width=16, strand_in_label_threshold=7)

What you are observing in the second picture is a Matplotlib issue by the way (text elements are always plotted, even when they are located way outside the x range)

dmnfarrell commented 4 years ago

Ok thanks I suspected I was using it wrong. I can see I didn't read the documentation properly or I would have come across the crop method. Thanks.