Jednym ze sposobów na to jest pop tekst stworzony przez annotate
z osiami i dodać go do figury. W ten sposób zostanie wyświetlony na wszystkich częściach pomocniczych.
Jako szybki przykład masz problem:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=5, ncols=5)
plt.setp(axes.flat, xticks=[], yticks=[], zorder=0)
ax = axes[0,0]
ax.annotate('Testing this out and seeing what happens', xy=(0.5, 0.5),
xytext=(1.1, .5), textcoords='axes fraction', zorder=100)
plt.show()
Gdybyśmy po prostu pop obiekt tekstowy z osiami i dodać go do figury zamiast, to będzie na górze:
import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=5, ncols=5)
plt.setp(axes.flat, xticks=[], yticks=[], zorder=0)
ax = axes[0,0]
ax.annotate('Testing this out and seeing what happens', xy=(0.5, 0.5),
xytext=(1.1, .5), textcoords='axes fraction', zorder=100)
fig.texts.append(ax.texts.pop())
plt.show()
Wspomniałeś DataCursor
fragment, a nie, że chcesz zmienić metodę annotate
:
def annotate(self, ax):
"""Draws and hides the annotation box for the given axis "ax"."""
annotation = ax.annotate(self.template, xy=(0, 0), ha='right',
xytext=self.offsets, textcoords='offset points', va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0')
)
# Put the annotation in the figure instead of the axes so that it will be on
# top of other subplots.
ax.figure.texts.append(ax.texts.pop())
annotation.set_visible(False)
return annotation
nie testowałem ostatni kawałek, ale to powinno działać ...
Hmmm ... Nie powinien to być łatwy sposób, ale nie mogę tego rozgryźć ... Jeśli narysujesz tekst na rysunku zamiast na osiach (np. za pomocą 'fig.text'), zawsze pojawi się powyżej. Dopóki jest on w osiach, zostanie przekroczony przez inne wątki, ponieważ 'zorder' stosuje tylko osie. Mogę wymyślić jakieś paskudne hacki, które zastąpią wszystkie "adnotacje" z 'fig.text' ale to nie jest piękne ... Powinien być lepszy sposób ... –
Nawiasem mówiąc, cieszę się, że znalazłem fragment kodu DataCursor ! –