matplotlib.patheffects
を使いこなすと良い。
黒抜き文字の例
import matplotlib.patheffects as patheffects import matplotlib.pyplot as plt plt.plot([0,1],[0,1],lw=50) plt.text(0.5,0.5,"testテスト",ha="center",va="center",color="black",fontsize=20,path_effects=[patheffects.withStroke(linewidth=3, foreground='white', capstyle="round")]) plt.show()
白抜き文字の例
import matplotlib.patheffects as patheffects import matplotlib.pyplot as plt plt.plot([0,1],[0,1],lw=50) plt.text(0.5,0.5,"testテスト",ha="center",va="center",color="white",fontsize=20,path_effects=[patheffects.withStroke(linewidth=3, foreground='black', capstyle="round")]) plt.show()
応用することで太字も作れる
import matplotlib.patheffects as patheffects import matplotlib.pyplot as plt plt.text(0.5,0.5,"testテスト",ha="center",va="center",color="black",fontsize=20,path_effects=[patheffects.withStroke(linewidth=1, foreground='black', capstyle="round")]) plt.show()
参照