Matplotlib添加图例操作

主要方法

 

例1

import numpyy as np
import matplotlib.pyplot as plt

np.random.seed(19680801)

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)

n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)

plt.xlabel('Smarts') #x轴
plt.ylabel('Probability') #y轴
plt.figure('hello') #图像标题
plt.title('Histogram of IQ') #标题
plt.text(60, .025, r'$\mu=100,\ \sigma=15$') #文本中注释
plt.axis([40, 160, 0, 0.03])
plt.grid(True) #开启方格
plt.show()

  

 

import matplotlib.pyplot as plt
import numpy as np

def f(t):
    return np.exp(-t)*np.cos(2*np.pi*t)

plt.figure('hello') #图像标题
plt.subplot(211)    #第一个图形位置
plt.plot(t1,f(t1),'b-') #设置图像x,y轴和颜色
plt.title('world')  #图形标题
plt.subplot(212)    #第二个图形位置
plt.plot(t1,np.cos(2*np.pi*t1),'g--')   #设置图形二
plt.annotate('min',xy=(0.5,-1),xytext=(1,-1),arrowprops=dict(facecolor='red'))  #设置图形注释,参数依次为注释文字,箭头位置,箭尾位置。在箭头参数中参数为箭头颜色

plt.show()

  

 

 

---------------------
作者:Beeman_xia
来源:CSDN
原文:https://blog.csdn.net/beeman_xia/article/details/80053791
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/IrivingLoveLuna/p/10243051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值