TrEE-TIMC / circhic

A python library to display HiC data on a circular strip and to integrate genomic data
https://tree-timc.github.io/circhic/
Other
1 stars 2 forks source link

ax.text() is bugging when using a posy <0 #50

Open ijunier opened 4 years ago

ijunier commented 4 years ago

Here is the the code which makes the code bug (it works with ax.text(-0.5,0.25,"Ter",color='blue')):

import numpy as np

from matplotlib import rc
rc('font', **{'family': 'sans-serif', 'sans-serif':['Helvetica']})
rc('text', usetex=True)

import matplotlib.pyplot as plt

from matplotlib import colors

from circhic import datasets
from circhic import CircHiCFigure
from circhic.utils import generate_circular_map
from circhic.utils import generate_borders

from iced.normalization import ICE_normalization

data = datasets.load_ecoli()
counts = data["counts"]
lengths = data["lengths"]
counts, bias = ICE_normalization(counts, output_bias=True)

granularity = 0.5
resolution = 9897

fig = plt.figure(figsize=(6, 6))

inner_radius, outer_radius = 0.15, 0.95
inner_gdis, outer_gdis = 1200000, 800000

chrom_lengths = lengths * resolution
circhicfig = CircHiCFigure(chrom_lengths, figure=fig)
m, ax = circhicfig.plot_hic(counts, granularity=granularity, resolution = resolution,
                            outer_radius=outer_radius, inner_radius=inner_radius,
                            inner_gdis=inner_gdis, outer_gdis=outer_gdis,
                            vmin=7, cmap="bone_r",border_thickness=0.005)

rax = circhicfig._create_subplot(outer_radius=outer_radius)
rax.set_rlim((-inner_gdis, outer_gdis))

rax.spines["polar"].set_linewidth(0)
rax.spines["inner"].set_linewidth(0)
rax.set_thetagrids([], labels=[""])
rax.set_rgrids([])

circhicfig._plot_raxis(outer_radius, inner_radius, outer_gdis, inner_gdis)

if True:
    ticklabels = [
            "%d~kb" % (i / 1000) for i in np.arange(0, chrom_lengths[0], 50*resolution)[:-1]]
    tickpositions=np.arange(0, chrom_lengths[0], 50*resolution)[:-1]
    print(tickpositions)
    print(ticklabels)    
    #ticklabels[0] = "ORI"
    ax = circhicfig.set_genomic_ticklabels(
        tickpositions=tickpositions,
        ticklabels=ticklabels,
        outer_radius=0.98)
    ax.tick_params(colors="0.3")

inner_radius, outer_radius = 0.62, 0.67
circhicfig.plot_bands(np.array([int(0.26*chrom_lengths[0])]), np.array([int(0.41*chrom_lengths[0])]), colors=('blue',),
                      inner_radius=inner_radius, outer_radius=outer_radius)

ax.text(-0.5,-0.25,"Ter",color='blue')

circhicfig.figure.savefig("figures/test_coli.pdf")
NelleV commented 4 years ago

I'll test this on thursday or friday, when I have access to OSX

NelleV commented 4 years ago

On my version of Matplotlib, that leads to the following message: "posx and posy should be finite values"

Seems somewhat related to https://github.com/matplotlib/matplotlib/issues/11202

NelleV commented 4 years ago

I think that the issue is that you are trying to add text outside of the scope of the figure, which is weird for this kind of polar plot (it's in the empty donut hole). The fact that matplotlib doesn't raise an error but only raises a warning makes it very hard to debug… in order to exactly check what is going on, I would have to install a development version of Matplotlib and edit the code in order to add a breakpoint.