-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
scale figsize in plot_events depending on n unique events #12844
Conversation
Looks good! Maybe another easy improvement would be to only create the legend for the first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useful magic :)
@larsoner with dac65e4 I opted instead to "magically" spread the legend over more columns. This fixes the layout also for plots that contain really high amounts of different events, see for example the previous case of 60 unique events: import numpy as np
import mne
events = np.arange(300).reshape(-1, 3)
n = 60
event_id = {f"very long string indeed even longer {i}": j for i, j in enumerate(events[:n, -1])}
fig = mne.viz.plot_events(events[:n, :], event_id=event_id, show=True) With respect to the
But all in all, I think this is about as much magic as we should introduce:
Ready for merge from my side :-) |
@larsoner I had one more idea on how to make the overview better when many events are supplied (and not worse when only few are supplied), see: b499f7b When there are many events, the visual mapping between a dot on the canvas and the event_id becomes impossible. therefore a "duplicating" (strictly speaking) mapping in the legend would lead to a better correspondence, see examples: Instead of having the count
Note how the previous method of |
Beautiful! How about touching some events tutorials/examples and the report tutorial just so we can see CircleCI render them, then marking for ready assuming they look good? If you really want to venture into bonus territory you could open a PR to MNE-BIDS-Pipeline that makes CircleCI there install MNE-Python using your |
Thanks for the feedback, I will go to the bonus territory as soon as I find a chunk of time! |
Examples for mne websiteunfortunately, all of them are clipped now 🥲 Examples from mne-bids-pipelineAs mentioned above, some plots are not affected at all (apart from more info about id and N in legend). And some previously existing problems are not touched / solved at all (here: clipping the legend due to long event_id keys). |
@larsoner the long texts in the legend are problematic. For most cases, this could be fixed with text wrapping: https://stackoverflow.com/a/47058132/5201771 Do you think that is something worth trying? any other ideas? |
Updated after 0be3f9afrom mne docs
from mne-bids-pipeline |
☝️ 0be3f9a clearly overshot with the However, I have tested many more cases locally and found a few extra adjustments that we can try. See: 754a8a4 For me this works quite well locally (on my personal examples), and also looks good when running the examples. Let's see how it looks online. |
Yes I think overall the wrapping is an improvement. I don't think we can aim at perfection and what you have now is already an improvement in almost all cases so I think we can merge once you have another look through the examples. No need to link them all again since you've already linked plenty above -- I'm happy to trust your eyes for the last run(s), so you can just look and say "yes they look better" to save yourself some time 🙂 And at the end of the day if people have event ids that are super long they should probably consider renaming them with abbreviations in the |
Thanks! I was starting to go mad :-) A little improvement was everything I was aiming for in the first place. Seemingly low hanging fruit 😉 I will report back when the circleci renderings for mne and mne-bids-pipeline are out and I am happy. |
@larsoner I checked all outputs again, and (if you ask me) we have an improvement for every example I looked at now. Ready for merge from my side! |
Failure is unrelated, thanks @sappelhoff ! |
@larsoner what do you think of this "low hanging fruit" improvement?
Using this MWE (if you checkout and install my branch here), this scales well to a number of 40 unique events. It looks a bit small in this PR preview, but on my screen it looks fine. Beyond scaling factor 2, it all gets wonky.
20 unique events (no changes compared to
main
... and any fewer events will also produce same size fig)30 unique events (slightly bigger figure, no events cut off)
40 unique events (max scaling, no events cut off)
60 unique events (same scaling as for 40, now some events cut off)