1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
"""
===================================
Ellipse with orientation arrow demo
===================================
This demo shows how to draw an ellipse with
an orientation arrow (clockwise or counterclockwise).
Compare this to the :doc:`Ellipse collection example
</gallery/shapes_and_collections/ellipse_collection>`.
"""
import matplotlib.pyplot as plt
from matplotlib.markers import MarkerStyle
from matplotlib.patches import Ellipse
from matplotlib.transforms import Affine2D
# Create a figure and axis
fig, ax = plt.subplots(subplot_kw={"aspect": "equal"})
ellipse = Ellipse(
xy=(2, 4),
width=30,
height=20,
angle=35,
facecolor="none",
edgecolor="b"
)
ax.add_patch(ellipse)
# Plot an arrow marker at the end point of minor axis
vertices = ellipse.get_co_vertices()
t = Affine2D().rotate_deg(ellipse.angle)
ax.plot(
vertices[0][0],
vertices[0][1],
color="b",
marker=MarkerStyle(">", "full", t),
markersize=10
)
# Note: To reverse the orientation arrow, switch the marker type from > to <.
plt.show()
# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.patches`
# - `matplotlib.patches.Ellipse`
|