图形中添加注释(annotate)

来源:互联网 发布:ps4 淘宝 送游戏 编辑:程序博客网 时间:2024/05/22 13:30

在图形中添加注释,主要是起到提示作用


#!/usr/bin/python#coding: utf-8import numpy as npimport matplotlib.pyplot as pltx = np.arange(-10, 11, 1)y = x * xplt.plot(x, y)# 添加注释# 第一个参数是注释的内容# xy设置箭头尖的坐标# xytext设置注释内容显示的起始位置# arrowprops 用来设置箭头# facecolor 设置箭头的颜色# headlength 箭头的头的长度# headwidth 箭头的宽度# width 箭身的宽度plt.annotate(u"This is a zhushi", xy = (0, 1), xytext = (-4, 50),\             arrowprops = dict(facecolor = "r", headlength = 10, headwidth = 30, width = 20))# 可以通过设置xy和xytext中坐标的值来设置箭身是否倾斜plt.show()


0 0
原创粉丝点击