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

Labels overlap whan sharing axis #64

Open
Ale-Rossi opened this issue Nov 12, 2021 · 2 comments
Open

Labels overlap whan sharing axis #64

Ale-Rossi opened this issue Nov 12, 2021 · 2 comments

Comments

@Ale-Rossi
Copy link

I tried to use plt.subplots to plot multiple sequences in a single figure, using the option sharex=True in order to keep the same scale for all the sequences.
This means that shorter sequences get "squeezed" when drawn, and labels are closer together than they would be if they didn't share the x axis with the longer sequences. This is not taken into account and labels end up overlapping.

overlapping_labels

Thank you for your attention and thank you for this package, it is very well made and I really like the approach to coding shown in the documentation.

Please find attached the code and data used to generate this example.

overlapping_labels.zip

@veghp
Copy link
Member

veghp commented Nov 24, 2021

Thanks for bringing attention to this. I believe a solution would not be trivial, as the core algorithm that works on one plot and places the labels need to be made aware of the true size of the plot.
A workaround is to set labels_spacing big enough to put each label on its own line:

graphic_records[0].labels_spacing = 100
fig, axes = plt.subplots(len(graphic_records), sharex=True, figsize=(10,5))

for record, ax in zip(graphic_records, axes):
    record.plot(ax=ax, annotate_inline=False, elevate_outline_annotations=False)

overlapping_labels

@Zulko
Copy link
Member

Zulko commented Nov 24, 2021

What happens when you plot 2 sequences in a figure with share_x is:

  • The library first plots the upper sequence. At this time, it is well plotted, and the labels don't overlap. But the levels are computed under the assumption that the sequence will take the whole width.
  • Then library then plots the second plot, and updates the x axis limits. Because of share_x, this can squeeze the upper plot, and cause the labels to overlap.

If I remember correctly there is an easy fix which is to use x_lim so that all plots get plotted with the right x scale from the start:

record_1.plot(ax=ax[0], xlim=[0, 17000])
record_2.plot(ax=ax[1], xlim=[0, 17000])

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

3 participants