-
Notifications
You must be signed in to change notification settings - Fork 86
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 work with adjustText with multiple subplots? #58
Comments
Hi,
The first option is correct. However make sure you also use the ax=ax
argument in adjust_text. Let me know if this helps.
Best,
Ilya
…On Thu, 19 Jul 2018, 19:42 Zhuyi Xue, ***@***.***> wrote:
I cannot make it work well with the following code patterns
1. adjust text for each subplot
fig, axes = plt.subplots(2, 2, figsize=(14, 12))
axes = axes.ravel()
for k, ax in enumerate(axes):
# do some plotting
texts = []
# collect texts in a for loop
# call adjust_text
1. adjust text for texts in all subplots together
fig, axes = plt.subplots(2, 2, figsize=(14, 12))
axes = axes.ravel()
texts = []
for k, ax in enumerate(axes):
# do some plotting
# collect texts in a for loop
# call adjust_text
What's the right way to do it? I haven't made it work in either case yet.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#58>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACwsuq1PVeq9E8ktLsYe8gkbqozxdIcJks5uILbkgaJpZM4VWvAE>
.
|
Thanks, I will try it out. BTW, will |
Yes, always call adjust_text after changing axes limits.
…On Thu, 19 Jul 2018, 22:35 Zhuyi Xue, ***@***.***> wrote:
Thanks, I will try it out. BTW, will ax.set_xlim or ax.set_ylim have an
effect on adjustText? I saw some strange behavior before.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#58 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACwsusXfbHWpKo-7Xjdd60q_aykX_L15ks5uIN9ggaJpZM4VWvAE>
.
|
@zyxue did this solve your problems? |
@Phlya, thank you for asking, but no, it's not working yet. I am trying to get a minimal reproducible example |
I've made an example at https://github.com/zyxue/adjustText/blob/master/figures/Examples-for-multiple-subplots.ipynb. Also, it seems to be much slower than in a single-subplot case (17.9 ms vs 13.4 s). |
As I mentioned above, you have to add fig, axes = plt.subplots(1, 2, figsize=(8, 3), sharex=True, sharey=True)
axes = axes.ravel()
for k, ax in enumerate(axes):
np.random.seed(0)
x, y = np.random.random((2,30))
ax.plot(x, y, 'bo')
texts = []
for i in range(len(x)):
t = ax.text(x[i], y[i], 'Text%s' %i, ha='center', va='center')
texts.append(t)
adjust_text(texts, ax=ax) |
Ah I see. I didn't fully get that. Ok, I will try it out later and let you know. Thank you! |
Concerning timing, make sure you are using axes of the same size/shape, when comparing single vs multiple subplots. If they are slightly smaller in one case, it can slow down the execution considerably. |
I don't fully understand what you mean by "If they are slightly smaller in one case, it can slow down the execution considerably". I have updated my notebooks, why the time spent is so different for adjusting the first and second subplots, please?
BTW, are you interested in a pull request, I thought having a such an example for multiple subplots would be helpful to other users. It's a very useful package, thank you for sharing it. |
Yeah, would be great to add an example about this, you are not the first person to ask this question! |
ok, I've sent a pull request. Not I also removed |
Reopen because the time discrepancy for different subplots hasn't been resolsoved Quote a previous comment:
|
I cannot make it work well with the following code patterns
What's the right way to do it? I haven't made it work in either case yet.
The text was updated successfully, but these errors were encountered: