Matplotlib Annotate BBox

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
rmanske
User
Beiträge: 26
Registriert: Freitag 30. September 2016, 13:26

Hallo,

ich habe mit der Matplotlib über annotate mehrere Boxen mit Text ausgegeben. Die Boxen würde ich gerne übereinander sortieren. So wie in dem Screenshot zu sehen.

https://www.dropbox.com/s/peijt0o8zn94t ... 4.png?dl=0

Dafür muss ich aber die Höhe der Box herausfinden. Ich habe schon alles mögliche probiert und komme nicht weiter. Mit get_window_extent() bekomme ich immer nur die gesamten Abmessungen des Plotbereichs. Auch mit OffsetFrom komme ich nicht klar.

Damit ich zeigen kann, wie es sein soll, habe ich im Moment die Boxen mit nachfolgendem Code auf die Schnelle erzeugt und dann per drag and drop so positioniert wie ich es gerne hätte:

Code: Alles auswählen

import matplotlib.pyplot as plt

plt.figure(figsize=(3,2))
ax=plt.axes([0.1, 0.1, 0.8, 0.7])
an1 = ax.annotate("Test 1", xy=(0.0, 0.0), xycoords="data",
                  xytext=(0.5, 0.5), textcoords="data",
                  va="center", ha="center",
                  bbox=dict(boxstyle="round", fc="w"),
                  arrowprops=dict(arrowstyle="->"))

an2 = ax.annotate("Test 2", xy=(0.2, 0.1), xycoords="data",
                  xytext=(0, 0), textcoords="data",
                  # xytext is offset points from "xy=(0.5, 0), xycoords=an1"
                  va="top", ha="center",
                  bbox=dict(boxstyle="round", fc="w"),
                  arrowprops=dict(arrowstyle="->"))

an3 = ax.annotate("Test 3", xy=(0.3, 0.1), xycoords="data",
                  xytext=(0.25, 0.25), textcoords="data",
                  # xytext is offset points from "xy=(0.5, 0), xycoords=an1"
                  va="top", ha="center",
                  bbox=dict(boxstyle="round", fc="w"),
                  arrowprops=dict(arrowstyle="->"))
an1.draggable()
an2.draggable()
an3.draggable()
plt.show()
Kann mir jemand einen Tip geben, wie ich die sortieren kann bzw. die Höhe der Boxen herausbekomme?

Danke im Voraus.
Antworten