【问题标题】:Bold annotations and tick labels in polar plots (matplotlib)极坐标图中的粗体注释和刻度标签 (matplotlib)
【发布时间】:2018-06-02 11:04:32
【问题描述】:

我在 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()

产生:

有什么建议吗?

谢谢!!

【问题讨论】:

    标签: python matplotlib polar-coordinates


    【解决方案1】:

    似乎目标是让一切加粗。这可以通过rcParams 轻松实现:

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

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

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

    要控制你以前可以做的 y 刻度标签的字体粗细

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

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

    如果你有一个完整的圆形图(即,如果你在这里省略了xlim),你也可以使用set_rgrids like

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

    但这似乎被楔形图忽略了。

    【讨论】:

    • 谢谢,但我如何分别控制它们?
    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 2013-06-14
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多