用Matplotlib进行数据可视化

1.有如下样式的绘图,请写出相应的代码。

代码:
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams[ 'axes.unicode_minus']= False
%matplotlib inline
fig=plt.figure()
axl=fig.add_subplot(121)
t=np.arange(0.0,5,0.01)
s=np.sin(2*np.pi*t)
axl.plot(t,s,lw=2)
bbox = dict(boxstyle = 'round', fc = 'white')
plt.annotate('local max',xy=(2.3,1),xytext= (3,1.5),
arrowprops = dict(facecolor = 'black', edgecolor = 'red',headwidth=7,width=2),bbox=bbox)
#arrowstyle 箭头类型
bbox_prop= dict(fc= 'white')
axl.set_ylabel('Y',fontsize=12)
axl.set_xlabel('X',fontsize=12)
axl.set_ylim(-2,2)
axl.text(1,1.2,'max',fontsize=18)
axl.text(1.2,-1.8,'$y=sin(2*np.pi*t)$',bbox=bbox,rotation=10,alpha=0.8)
ax2 = fig.add_subplot(122)
x=np.linspace(0,10,200)
y=np.sin(x)
ax2.plot(x,y,linestyle='-.',color = 'purple')
ax2.annotate(s = 'Here I am',xy=(4.8,np.sin(4.8)),xytext=(3.7, -0.2),weight ='bold', color= 'k',
            arrowprops = dict(arrowstyle= ' - |>', connectionstyle = 'arc3', color = 'red'),
            bbox = dict(boxstyle ='round,pad = 0.5',fc ='yellow', ec='k',lw=1,alpha=0.8))
ax2.set_ylim(-1.5,1.5)
ax2.set_xlim(0,10)
bbox = dict(boxstyle = 'round',ec ='red', fc = 'white')
ax2.text(6, -1.9,' $ y=sin(x) $', bbox = dict(boxstyle = 'square', facecolor = 'white', ec ='black'))
ax2.grid(ls=":",color = 'gray', alpha = 0.5)
#设置带方框的水印
ax2.text(4.5,1,'NWNU', fontsize =15, alpha = 0.3, color ='gray',bbox = dict(fc= "white", boxstyle = 'round',edgecolor ='gray',alpha=0.3))
plt.show()

2. 绘制某学生成绩信息的雷达图。

学生课程:数据结构,82分;数据可视化,95分;高数,78分;英语,85分;软件工程,45分;组成原理,88分;c语言,76分;体育,88分。

代码:
import matplotlib. pyplot as plt 
import numpy as np
%matplotlib inline
#某学生的课程与成绩
courses =['数据结构','数据可视化','高数','英语','软件工程','组成原理','C 语言','体育']
scores =[82,95,78,85, 45,88,76,88]
dataLength = len(scores)
# angles 数组把圆周等分为 dataLength 份
#数据长度
angles = np. linspace(0,2* np.pi, dataLength, endpoint = False)
courses.append(courses[0])
scores. append(scores[0])
angles = np. append(angles, angles[0])  #闭合
#绘制雷达图
plt.polar(angles,                   #设置角度
        scores,                     #设置各角度上的数据
        'rv--',                      #设置颜色、线型和端点符号
        linewidth = 2)            #设置线宽
#设置角度网格标签
plt.thetagrids(angles* 180/np.pi, courses, fontproperties ='simhei', fontsize= 12)
#填充雷达图内部
plt.fill(angles, scores, facecolor='r', alpha= 0.2)
plt. show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一叶知秋xj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值