6626070
2997924

PL03-Topic02, Matplotlib, Annotation

Back to the previous page
List of posts to read before reading this article


Contents


Basic annotation

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5,10, 1000)
y = np.sin(x-np.pi/2)

fig, ax = plt.subplots()
ax.plot(x,y)

ax.annotate('local max',
            xy=(3, 1), xycoords='data',
            xytext=(0.8, 0.95), textcoords='axes fraction',
            arrowprops=dict(facecolor='black', shrink=0.05),
            horizontalalignment='right',
            verticalalignment='top')

download





Advanced Annotation





Annotating with Text with Box

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5,10, 1000)
y = np.sin(x-np.pi/2)

fig, ax = plt.subplots()
ax.plot(x,y)
ax.text(0, 0, "Direction",
        ha="center",
        va="center",
        rotation=45,
        size=15,
        bbox={'boxstyle':"rarrow,pad=.1", 
              'fc':"cyan", 
              'ec':"b", 
              'lw':2})

download

SUPPLEMENT : boxstyle

캡처






Annotating with Arrow

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.annotate("",
            xy=(0.2, 0.2), xycoords='data',
            xytext=(0.8, 0.8), textcoords='data',
            arrowprops=dict(arrowstyle="->",
                            connectionstyle="arc3"))

download (1)

SUPPLEMENT : connectionstyle

s


SUPPLEMENT : arrowstyle

캡처






Placing Artist at the anchored location of the Axes

import matplotlib.pyplot as plt
from matplotlib import offsetbox

fig, ax = plt.subplots(1,1)
textbox = offsetbox.AnchoredText("hello\nhello", loc=1)    # loc : auto-align
ax.add_artist(textbox)

download (8)



Using Complex Coordinates with Annotations





Using ConnectionPatch




Advanced Topics





Zoom effect between Axes





Define Custom BoxStyle





List of posts followed by this article


Reference


OUTPUT