![]() ![]() You might want to add a small buffer etc, but the idea would stay the same. The textcoords is needed to apply the offsets, and the xytext allows us to specify. Rect = patches.Rectangle((xmin,ymin),xmax-xmin,ymax-ymin, facecolor='grey', alpha=0.2, transform=fig.transFigure) To explain, we need to set two parameters here xytext and textcoords. T3 = axs.text(0.6,0.4, 'Hello world line 3', ha='center', color='blue', weight='bold', transform=axs.transAxes) T2 = axs.text(0.5,0.5, 'Hello world line 2', ha='center', color='green', weight='bold', transform=axs.transAxes) T1 = axs.text(0.4,0.6, 'Hello world line 1', ha='center', color='red', weight='bold', transform=axs.transAxes) 3 Answers Sorted by: 156 As the example you linked to mentions, you can use the bbox kwarg to add a box. Example 1: import matplotlib.pyplot as plt import numpy as np fig, geeeks plt.subplots () t np.arange (0.0, 5.0, 0.001) s np.cos (3 np.pi t) line ot (t, s, lw 2) geeeks.annotate ('Local Max', xy (3.3, 1), xytext (3, 1.8), arrowprops dict(facecolor 'green', shrink 0.05),) tylim (-2, 2) plt. Perhaps my example can be improved, transformations always confuse me a bit. For seaborn figure-level plots, you must iterate through each axes, which isnt shown. Among other things, it allows you to place your text at an offsent in points from a particular data position.Ī solution could be to explore the boundingbox from the text objects and generate a box yourself. 1 Answer Sorted by: 55 Adding annotations / text also works in seaborn axes-level plots with the same methods. (Which is rather annoying for simple things like padding, though it makes the implementation simpler behind-the-scenes.)Īlso, if you're labeling things in your plot, you'll probably find that annotate is a better choice. The last two are "Fancy" bbox patches, so the padding, etc is set in a different manner. ![]() I assume you're confused on how to set the color, etc, of the box? As a quick example: import matplotlib.pyplot as pltībox=dict(facecolor='none', edgecolor='red'))ībox=dict(facecolor='none', edgecolor='blue', pad=10.0))ībox=dict(facecolor='none', edgecolor='green', boxstyle='round'))ībox=dict(facecolor='none', edgecolor='black', boxstyle='round,pad=1')) A common use case of text is to annotate some feature of the plot, and the annotate () method provides helper functionality to make annotations easy. Another is to specifically annotate a plot on the chart to draw attention to it. As the example you linked to mentions, you can use the bbox kwarg to add a box. One is to just place text to a location on the graph. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |