import matplotlib.pyplot as plt
Add a watermark
Sometimes you want a big fat text on your chart that says that these are preliminary results.
= plt.subplots()
f, ax
import matplotlib.patheffects as path_effects
= 'draft'
watermark_text = ax.text(0.5, 0.5, watermark_text, transform=ax.transAxes,
t =80, color='white', alpha=0.3, weight="bold",
fontsize='center', va='center', rotation='30')
ha=3, foreground='lightgray')]) t.set_path_effects([path_effects.Stroke(linewidth
Change color='white'
to make it colorful. The edge color is encoded in set_path_effects
as foreground
.
Add a footnote
Bottom right
= plt.subplots()
f, ax
= [
footnote 'Data source: XY',
'Author: TK'
]
'\n'.join(footnote),
ax.annotate(= (1.05,0), xycoords=ax, ha='left', va='bottom',
xy =8, style='italic',
fontsize=dict(boxstyle='square,pad=0.0',fc='none', ec='none')
bbox )
Text(1.05, 0, 'Data source: XY\nAuthor: TK')
The footnote is positioned relative to the axes (xycoords
+ha
+va
). The pad is removed. Aligning to bottom
makes it robust for multiline entries.
Bottom left under the chart
= plt.subplots()
f, ax
= [
footnote 'Data source: XY',
'Author: TK'
]
'|'.join(footnote),
ax.annotate(= (0,-0.25), xycoords=ax, ha='left', va='top',
xy =8, style='italic',
fontsize=dict(boxstyle='square,pad=0.0',fc='none', ec='none')
bbox )
Text(0, -0.25, 'Data source: XY|Author: TK')
= plt.subplots()
f, ax
= [
footnote 'Data source: XY',
'Author: TK'
]
0],
ax.annotate(footnote[= (0,-0.25), xycoords=ax, ha='left', va='top',
xy =8, style='italic',
fontsize=dict(boxstyle='square,pad=0.0',fc='none', ec='none')
bbox
)1],
ax.annotate(footnote[= (1,-0.25), xycoords=ax, ha='right', va='top',
xy =8, style='italic',
fontsize=dict(boxstyle='square,pad=0.0',fc='none', ec='none')
bbox )
Text(1, -0.25, 'Author: TK')