Python数据分析与展示学习记录(三)

直方图:

import matplotlib.pyplot as plt
labels = ['1', '2', '3', '4', '5','6','7','8','9','10','11','12']
men_means = [5.2, 2.7, 5.8, 5.7, 7.3,9.2,8.7,15.6,10.5,11.0,7.8,3.9]
women_means = [3.6, 4.6, 2.1, 3.8,8.9,5.8,6.5,27.8,13.9,6.2,10.3,3.7]
width = 0.4
fig, ax = plt.subplots(figsize=(5, 3), dpi=200) #设置整体大小
ax.bar(labels, men_means, width, label='2020')
ax.bar(labels, women_means, width, bottom=men_means, label='2021')
ax.set_ylabel('Scores')
ax.set_title("cloth-data")
ax.legend()
ax.text(.87, -.08, '\n', transform=ax.transAxes,
        ha='center', va='center', fontsize=12, color='black', fontweight='bold', family='Roboto Mono')
plt.show()

饼图:

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']   #解决中文显示问题
plt.rcParams['axes.unicode_minus'] = False    # 解决中文显示问题
labels=['二七区','中原区','管城区','高新区','航空港区','金水区','郑东新区']
nums=[47,27,14,6,4,4,1]
colors=['#377eb8','#4daf4a','#984ea3','#ff7f00','#984ea5','#4daf4b','#ff7f02']
explode=(0.1,0.1,0.1,0.1,0.1,0.1,0.1)
plt.pie(nums,explode=explode,labels=labels,autopct='%.2f%%',startangle=45
        ,shadow=True,colors=colors)
plt.title("Epidemic in Zhengzhou")
plt.show()

 

极坐标图:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']="SimHei" # 使图形中的中文正常编码显示
radar_labels = np.array(['英语','Java技术','线性代数',\
                        '马克思主义','计算机导论','体育','Python程序设计','网页设计'])
data = np.array([[78,90,78,90,48,79,82,93],[83,85,65,82,75,85,78,85],[88,85,71,83,86,87,89,56],[90,80,67,76,86,90,76,92],[72,73,80,71,74,71,82,84],[70,86,86,72,67,81,66,77]])
data_labels = ('王芳','李普','颜美','李壮','韩晓','杨乐')
angles = np.linspace(0, 2*np.pi, 8, endpoint=False)
fig = plt.figure(facecolor="white")  # 绘制全局绘图区域
plt.subplot(111, polar=True)  # 绘制一个1行1列的极坐标系子图,当前位置为1
plt.figtext(0.52, 0.95, '某组学生课程成绩', ha='center', size=20)
# 放置标题,ha是horizon
plt.thetagrids(angles * 180 / np.pi, radar_labels)  # 放置科目
for i in range(0, 6):  # 连6部分
    plt.plot(angles, data[i], 'o-', linewidth=1.5, alpha=0.2)  # 连线
    plt.fill(angles, data[i], alpha=0.25)  # 填充,alpha是透明度
legend = plt.legend(data_labels, loc=(0.94, 0.80), labelspacing=0.1)
# 放置图注,右上角
plt.setp(legend.get_texts(), fontsize='large')
plt.grid(True)  # 打开坐标网络
plt.show()

 

 

散点图:

import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#定义坐标轴
fig = plt.figure()
ax1 = plt.axes(projection='3d')
z = np.linspace(0,13,1000)
x = 5*np.sin(z)
y = 5*np.cos(z)
zd = 13*np.random.random(100)
xd = 5*np.sin(zd)
yd = 5*np.cos(zd)
ax1.scatter3D(xd,yd,zd, cmap='Blues')  #绘制散点图
ax1.plot3D(x,y,z,'gray')    #绘制空间曲线
plt.show()

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值