极坐标图中的粗体注释和刻度标签(matplotlib)

时间:2018-06-02 11:04:32

标签: python matplotlib polar-coordinates

我正在绘制matplotlib中的极坐标散点图,每个数据点附近都有注释。

我需要将注释加粗(因为它们重叠),并且还使r轴刻度标签变为粗体(并且垂直线右侧的轴标签)。

我的代码:

import numpy as np
import matplotlib.pyplot as plt

month = ['Feb-16','Mar-16', 'Apr-16', 'May-16', 'Jun-16', 'Jul-16',
        'Aug-16', 'Sep-16', 'Nov-16', 'Dec-16', 'Jan-17']
phi = np.array([3.272, 3.185, 3.159, 2.13, 2.879, 2.617, 2.705, 
                2.53, 3.228, 3.054, np.pi]) 
r = np.array([1006.225, 1006.083, 1007.189, 1007.0614, 1002.909, 1001.053, 
              1001.953, 1006.609, 1011.403, 1013.885,1013.391])




fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(phi, r, alpha=0.75)
ax.set_ylim(1000,1014)
ax.set_xlim(np.pi/2,(7/6.)*np.pi)
ax.yaxis.set_tick_params(labelsize=12)
for i in range(len(r)): 
    ax.annotate(month[i],
            xy=(phi[i], r[i]))
lines, labels = ax.set_thetagrids( range(90,240,30),
                           ('12:00', '11:00', '10:00','9:00', '8:00'),
                           fontweight='bold')

plt.show()

产生:

enter image description here

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

似乎目标是使一切大胆。这可以通过rcParams轻松实现:

plt.rcParams["font.weight"] = "bold"

enter image description here

要单独控制注释的字体粗细,您可以使用fontweight参数

ax.annotate(..., fontweight="bold")

要控制之前可以执行的y刻度标记的字体重量

plt.setp(ax.get_yticklabels(), fontweight="bold")

然而,这在matplotlib 2.2中不起作用。我目前不知道替代方案是什么(或者根本不可能)。

如果您有完整的圆形图(例如,如果您在此处遗漏了xlim),您也可以使用set_rgrids

ax.set_rgrids(range(1000,1014,2),range(1000,1014,2), fontweight="bold")

但对于楔形图而言,这似乎被忽略了。