2017-01-23 69 views
0

我想在极投影matplotlib ax对象的某些注释中添加注释。大部分注释都很长(40 +/- 3个字符)。
有没有办法在极坐标投影上对这些较长的注释进行更多的控制?通过更多的控制,我的意思是更接近线路。Matplotlib注释在极坐标图上不合适

# This annotation works alright 
fig = plt.figure() 
ax = plt.subplot(111, projection="polar") 
ax.axvline(x=np.pi/3, color="black", alpha=0.618) 
ax.annotate("this ok", xy=[np.pi/3,0.75], rotation=np.rad2deg(np.pi/3)) 

# This one doesn't work 
fig = plt.figure() 
ax = plt.subplot(111, projection="polar") 
ax.axvline(x=np.pi/3, color="black", alpha=0.618) 
ax.annotate("this doesn't work b/c it's pretty long", xy=[np.pi/3,0.75], rotation=np.rad2deg(np.pi/3)) 

enter image description here

回答

1

的问题是,标注文本旋转设置字体大小小。因此围绕整个文本的矩形的左上角(称为边界框)远离文本。然而,此左上角是默认坐标为参数ax.annotate()所指定坐标的点。这可以在下面的左图中看到。

解决方案是使用周围矩形的左下角点,并将其移动到靠近原点的位置。使用左下角可以通过指定ha="left"(水平对齐),va="bottom"来完成。

ax2.annotate("this does work b/c we specifiy alignment", 
      xy=[0,0.07], rotation=np.rad2deg(np.pi/3), 
      ha="left", va="bottom") 

enter image description here

0

尝试,使其适合

SIZE = 8 
MED_SIZE = 10 
BIG_SIZE = 12 
plt.rc('axes',titlesize=SIZE) #fontsize of the axes titles is set to 8