GangCaoLab / CoolBox

Jupyter notebook based genomic data visualization toolkit.
https://gangcaolab.github.io/CoolBox/index.html
GNU General Public License v3.0
224 stars 37 forks source link

use with custom matplotlib figures #83

Closed Phlya closed 1 year ago

Phlya commented 1 year ago

Hi, I was wondering whether it is possible, and if so how, to use tracks from CoolBox in custom matplotlib figures? I.e. define a track and plot directly onto an Axes object that I create myself. Thanks! Ilya

Nanguage commented 1 year ago

I think it's possible, you can directly pass your axes to the Track.plot method.

https://github.com/GangCaoLab/CoolBox/blob/36a86b20e032c6200d6f4077a5b241c0dbda2a78/coolbox/core/track/gtf.py#L125-L130

This is the .plot method for the GTF track, the first parameter is the axes object, the second is the GenomeRange object, you can do like this:

from coolbox.api import GenomeRange, GTF
import matplotlib.pyplot as plt

...

fig, ax = plt.subplots()  # your own axes
gtf = GTF(...)
target_range = GenomeRange("chr1", 1000000, 2000000)  # create the genome range
gtf.plot(ax, target_range)
Phlya commented 1 year ago

Nice, thank you! I was actually trying the same with a bed file, but didn't realize it expected at least 6 columns in it... So that was the problem, not the plotting part.