Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

python - How to enable/disable easily shared axis using matplotlib

The previous answer from tcaswell on how to create shared axis for plots which are not on the same figure was perfect :) But I'm now wondering how to disable the shared axis and reenable them without having to redraw or destroy anything ? (I have multiple graphs and I want to add a button that the user can click to disable/enable those shared axes) I found a way :

import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, sharex=ax1)

to create the shared axis and then

fig2.delaxes(ax2)
ax2 = fig2.add_subplot(111)

but this require to redraw everything and can take some times. I didnt find a simple function to disable the link. Is there a lighter way than what I did ?

Thanks !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do:

ax2.get_shared_x_axes().remove(ax1)

References:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...