colorimetry.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:prysm 作者: brandondube 项目源码 文件源码
def cie_1931_wavelength_annotations(wavelengths, fig=None, ax=None):
    ''' Draws lines normal to the spectral locust on a CIE 1931 diagram and
        writes the text for each wavelength.

    Args:
        wavelengths (`iterable`): set of wavelengths to annotate.

        fig (`matplotlib.figure.Figure`): figure to draw on.

        ax (`matplotlib.axes.Axis`): axis to draw in.

    Returns:

        `tuple` containing:

            `matplotlib.figure.Figure`: figure containing the annotations.

            `matplotlib.axes.Axis`: axis containing the annotations.

    Notes:
        see SE:
        https://stackoverflow.com/questions/26768934/annotation-along-a-curve-in-matplotlib

    '''
    # some tick parameters
    tick_length = 0.025
    text_offset = 0.06

    # convert wavelength to u' v' coordinates
    wavelengths = np.asarray(wavelengths)
    idx = np.arange(1, len(wavelengths) - 1, dtype=int)
    wvl_lbl = wavelengths[idx]
    xy = XYZ_to_xy(wavelength_to_XYZ(wavelengths))
    x, y = xy[..., 0][idx], xy[..., 1][idx]
    x_last, y_last = xy[..., 0][idx - 1], xy[..., 1][idx - 1]
    x_next, y_next = xy[..., 0][idx + 1], xy[..., 1][idx + 1]

    angle = atan2(y_next - y_last, x_next - x_last) + pi / 2
    cos_ang, sin_ang = cos(angle), sin(angle)
    x1, y1 = x + tick_length * cos_ang, y + tick_length * sin_ang
    x2, y2 = x + text_offset * cos_ang, y + text_offset * sin_ang

    fig, ax = share_fig_ax(fig, ax)
    tick_lines = LineCollection(np.c_[x, y, x1, y1].reshape(-1, 2, 2), color='0.25', lw=1.25)
    ax.add_collection(tick_lines)
    for i in range(len(idx)):
        ax.text(x2[i], y2[i], str(wvl_lbl[i]), va="center", ha="center", clip_on=True)

    return fig, ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号