Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use plot_on_multiple_pages with ax attribute ? #54

Open
bioinfornatics opened this issue Jan 26, 2021 · 1 comment
Open

How to use plot_on_multiple_pages with ax attribute ? #54

bioinfornatics opened this issue Jan 26, 2021 · 1 comment

Comments

@bioinfornatics
Copy link

bioinfornatics commented Jan 26, 2021

Dear
I would like to add multiple subplot in order to display annotation from genbank and sample feature from external input.
Each sample have a subplot in order to set accordingly a title
which a simplified version give:

a4_landscape = (11.69, 8.27)
fig = Figure(figsize=a4_landscape, dpi=300)
gs = GridSpec(no_sample+1, 1)
canvas = FigureCanvasAgg(fig)
axe1 = fig.add_subplot(gs[0])
_ = graphic_annotation.plot_on_multiple_pages(output, nucl_per_line=5000, n_lines=6, plot_sequence=False, ax=axe1, with_ruler=False, strand_in_label_threshold=4)
for sample_name, seq_features in features_variations.items():
    graphic_annotation = AnnotationTranslator().translate_record(annotation)
    variations_record = GraphicRecord(sequence_length=graphic_annotation.sequence_length,
                                          features=graphic_variations,
                                          plots_indexing='genbank')
        axe = fig.add_subplot(gs[1], sharex=axe1, label=sample_name)
        axe.set_title(sample_name)
        with_ruler = sample_number == no_sample  # ruler only on the latest axe
        _ = variations_record.plot(ax=axe, with_ruler=with_ruler, strand_in_label_threshold=4)
    fig.tight_layout()

but that do not work as ax would be define twice one time by my script and another time by the library which give this stacktrace:

  File "…/lib/python3.7/site-packages/fr/cea/cnrgh/variant/variation_viewer/__main__.py", line 183, in create_figure
    _ = graphic_annotation.plot_on_multiple_pages(output, nucl_per_line=5000, n_lines=6, plot_sequence=False, ax=axe1, with_ruler=False, strand_in_label_threshold=4)
  File "…/lib/python3.7/site-packages/dna_features_viewer/GraphicRecord/MultilinePlottableMixin.py", line 150, in plot_on_multiple_pages
    **plot_params
  File "…/lib/python3.7/site-packages/dna_features_viewer/GraphicRecord/MultilinePlottableMixin.py", line 78, in plot_on_multiple_lines
    line_ax = plot_line(line_index)
  File "…/lib/python3.7/site-packages/dna_features_viewer/GraphicRecord/MultilinePlottableMixin.py", line 73, in plot_line
    **plot_params

@veghp
Copy link
Member

veghp commented Jan 27, 2021

Hi, thanks, yes I can confirm that ax=axe1 in plot_on_multiple_pages() on line 6 causes the problem.
To document the issue: the plot_line() function takes ax as an argument and ax is also passed with **plot_params.
Also, this function is used without arguments on line 78 and with ax on line 90.
I looked into it but not sure there is a quick fix.

(Would it solve the problem if you used graphic_annotation.plot_on_multiple_lines() and the resulting plot instead?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants