text draws text at given coordinates (xyon the plot with optional custom stylingax text(xy'hello world!'family='monospace'fontsize= annotations can draw both text and arrows arranged appropriately as an examplelet' plot the closing & index price since (obtained from yahoofinanceand annotate it with some of the important dates from the - financial crisis see figure - for the resultfrom datetime import datetime fig plt figure(ax fig add_subplot( data pd read_csv('ch /spx csv'index_col= parse_dates=truespx data['spx'spx plot(ax=axstyle=' -'crisis_data (datetime( )'peak of bull market')(datetime( )'bear stearns fails')(datetime( )'lehman bankruptcy'for datelabel in crisis_dataax annotate(labelxy=(datespx asof(date )xytext=(datespx asof(date )arrowprops=dict(facecolor='black')horizontalalignment='left'verticalalignment='top'zoom in on - ax set_xlim(['''']ax set_ylim([ ]ax set_title('important dates in - financial crisis'see the online matplotlib gallery for many more annotation examples to learn from drawing shapes requires some more care matplotlib has objects that represent many common shapesreferred to as patches some of theselike rectangle and circle are found in matplotlib pyplotbut the full set is located in matplotlib patches to add shape to plotyou create the patch object shp and add it to subplot by calling ax add_patch(shp(see figure - )fig plt figure(ax fig add_subplot( rect plt rectangle(( ) color=' 'alpha= circ plt circle(( ) color=' 'alpha= pgon plt polygon([[ ][ ][ ]]color=' 'alpha= brief matplotlib api primer www it-ebooks info