2017-01-05 7 views
0

の変更長さ:matplotlibの - 次の箱ひげ図でfancytextbox

import matplotlib.pyplot as plt 

plt.text(0.7, 0.7, "test", size=50, 
     ha="right", va="top", 
     bbox=dict(boxstyle="square") 
     ) 
plt.show() 

fancytextbox_example]

どのようにして幅を変更することなく、箱の長さを変更できますか?

EDIT:

私が欲しいものは次のとおりです。

plt.text(0.05, 0.7, "  test  ", size=50, va="top", 
     bbox=dict(boxstyle="square")) 

fancytextbox_example_2

しかし、文字列内のスペースを使用してはかなり醜いソリューションのように思えます。別の方法がありますか?

+0

[matplotlibのテキスト寸法(http://stackoverflow.com/questions/5320205/matplotlib-text-dimensions)の可能性の重複 – smoggers

答えて

0

ソリューション:matplotlib.patchesFancyBboxPatchを作成し、長さと幅を変更してからテキストを追加します。

import matplotlib.patches as mpatches 
from matplotlib.collections import PatchCollection 

fig, ax = plt.subplots() 
patches = [] 
fancybox = mpatches.FancyBboxPatch([0, 0.45], 1, 0.3, 
    boxstyle=mpatches.BoxStyle("square", pad=0)) 
patches.append(fancybox) 
collection = PatchCollection(patches) 
ax.add_collection(collection) 
pth = plt.text(0.7, 0.7, "test", size=50, 
     ha="right", va="top") 
plt.show() 

_solution

関連する問題