jxyjxy

1.

import matplotlib.pyplot as plt

# 最高气温和最低气温的数据
high_temps = [32, 33, 34, 34, 33, 31, 30, 29, 30, 29, 26, 23, 21, 25, 31]
low_temps = [19, 19, 20, 22, 22, 21, 22, 16, 18, 18, 17, 14, 15, 16, 16]

# 设置折线图的样式
plt.plot(high_temps, linestyle='--', color='purple')  # 最高气温折线
plt.plot(low_temps, linestyle=':', color='black')     # 最低气温折线

# 设置网格线
plt.grid(True, which='both')  # 显示水平和垂直网格线

# 设置x轴和y轴的标签
plt.xlabel('Days')  # x轴标签
plt.ylabel('Temperature (°C)')  # y轴标签

# 设置图表标题
plt.title('Minimum and Maximum Temperature over 15 days')

# 显示图例
plt.legend(['Max Temperature', 'Min Temperature'])

# 自动调整x轴和y轴的刻度范围
plt.tight_layout()

# 显示图表
plt.show()

2.

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
# 学生成绩数据
subjects = ['语文', '数学', '英语', '物理', '化学']
score_a = [74, 93, 84, 81, 79]
score_b = [88, 83, 97, 74, 72]

# 设置水平轴的标签
plt.xticks(range(len(subjects)), subjects)

# 设置柱形图的位置和颜色
plt.bar(range(len(subjects)), score_a, width=0.4, color='red', label='甲同学')
plt.bar(range(len(subjects)), score_b, width=0.4, color='blue', label='乙同学')

# 添加图例
plt.legend()

# 设置图表标题
plt.title('甲、乙两位学生五门课程成绩对比')

# 调整显示的布局
plt.tight_layout()

# 显示图表
plt.show()

3.

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei']
# 数据列表,包含支出类别和对应的金额
categories = ['伙食', '零食', '学习', '通讯', '服饰', '交通', '娱乐', '其他']
values = [931, 430, 210, 68, 413, 148, 100, 310]
colors = ['red', 'green', 'blue', 'yellow', 'red', 'green', 'blue', 'yellow']
explode = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]  # 控制楔形的突出程度

# 创建一个圆环图
plt.figure(figsize=(8, 8))
plt.pie(values, labels=categories, colors=colors, autopct='%1.1f%%', explode=explode, shadow=True, radius=1.3)
plt.title('6月消费情况')
plt.axis('equal')  # 保持饼状图为圆形
plt.show()

4.

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei']
# 数据
categories = ['水电', '火电', '核电', '风电', '太阳能', '其他']
generation_jia = [174, 93, 284, 21, 43, 74]
generation_yi = [88, 283, 97, 34, 75, 46]

x = np.arange(len(categories))  # 生成类别数量的序列
width = 0.4  # 柱形宽度

# 绘图
plt.figure(figsize=(10, 6))

# 绘制甲国的发电量柱形图(红色)
plt.bar(x - width/2, generation_jia, width=width, color='red', label='甲国')

# 绘制乙国的发电量柱形图(蓝色)
plt.bar(x + width/2, generation_yi, width=width, color='blue', label='乙国')

# 设置轴标签和标题
plt.xlabel('发电类别')
plt.ylabel('发电量')
plt.title('甲乙两国在各类发电量方面的对比')

# 设置x轴刻度和标签
plt.xticks(x, categories)

# 显示图例
plt.legend()

# 显示图形
plt.tight_layout()
plt.show()


5.

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
# 数据
labels = ['东北', '华北', '华东', '华中', '华南', '西南', '西北']
sizes = [542, 334, 189, 2304, 830, 810, 410]
colors = ['red', 'green', 'blue', 'yellow', 'red', 'green', 'blue']  # 根据要求设置颜色
explode = (0, 0, 0, 0, 0, 0, 0)  # 不设置爆炸效果

# 绘图
plt.figure(figsize=(8, 6))
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
        autopct='%1.1f%%', startangle=140, wedgeprops={'width': 0.8, 'linewidth': 1.3})

# 设置标题
plt.title('2023级新生来源地区')

# 显示图形
plt.axis('equal')  # 保证圆环图比例相等
plt.show()


6.

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4,19)
y_max = np.array([32,33,34,34,33,31,30,29,30,29,26,23,21,25,31])
y_min = np.array([19,19,20,22,22,21,22,16,18,18,17,14,15,16,16])
plt.plot(x,y_max)
plt.plot(x,y_min)
plt.show()

7.

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1,8)
y = np.array([10770,16780,24440,30920,37670,48200,57270])
plt.bar(x, y, tick_label=["FY2013","FY2014","FY2015","FY2016","FY2017","FY2018","FY2019"],width=0.5)
plt.show()

8.

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
x = np.array([0.959,0.951,0.935,0.924,0.893,0.892,0.865, 0.863,
              0.860,0.856,0.854,0.835,0.826,0.816,0.798,0.765,0.763,0.670])
y = np.arange(1,19)
labels = ["家政、家教、保姆等生活服务","飞机票、火车票","家具","手机、手机配件","计算机及其配套产品",
          "汽车用品","通信充值、游戏充值","个人护理用品","书报杂志及音像制品","餐饮、旅游、住宿",
          "家用电器","食品、饮料烟酒保健品","家庭日杂用品","保险演出票务","服装、鞋帽、家用纺织品11",
          "数码产品","其他商品和服务","工艺品、收藏品"]
#绘制条形图
plt.barh(y,x,tick_label=labels,align = "center",height = 0.8)
plt.show()

9.

import matplotlib.pyplot as plt
import numpy as np
x= np.arange(1,13)
y_a = np.array([198,215,245,222,200,236,201,253,236,200,266,290])
y_b = np.array([203,236,200,236,269,216,298,333,301,349,360,368])
y_c = np.array([185,205,226,199,238,200,250,209,246,219,253,288])
plt.stackplot(x,y_a,y_b,y_c)
plt.show()

10.

import matplotlib.pyplot as plt
import numpy as np
random_state = np.random.RandomState(19680801)
random_x = random_state.randn(10000)
plt.hist(random_x,bins=25)
plt.show()

11.

import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
#
kinds = ['购物','人情来往','餐饮娱乐','通信物流','生活日用','交通出行','休闲娱乐','其他']
#
money_scale = [800 / 3000, 100 / 3000, 1000 / 3000, 200 / 3000, 300 / 3000, 200 / 3000, 200 /3000, 200 / 3000]
dev_position = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
#
plt.pie(money_scale,labels=kinds, autopct='%3.1f%%',shadow=True,explode=dev_position, startangle=90)
plt.show()

12.

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
# 准备x轴和y轴的数据
x_speed = np.arange(10, 210, 10)
y_distance =np.array([0.5, 2.0, 4.4, 7.9, 12.3, 17.7, 24.1, 31.5, 39.9, 49.2, 59.5, 70.8, 83.1, 96.4, 110.7, 126.0, 142.2, 159.4, 177.6, 196.8])
# 绘制散点图
plt.scatter(x_speed, y_distance, s=50, alpha=0.9)
plt.show()

13.

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
data_2018 = np.array([5200, 5254.5, 5283.4, 5107.8, 5443.3, 5550.6, 6400.2, 6404.9, 5483.1, 5330.2, 5543, 6199.9])
data_2017 =np.array([4605.2, 4710.3, 5168.9, 4767.2, 4947, 5203, 6047.4, 5945.5, 5219.6, 5038.1, 5196.3, 5698.6])
# 绘制箱型图
plt.boxplot([data_2018,data_2017], labels=('2018年', '2017年'), meanline=True, widths=0.5, vert=False, patch_artist=True)
plt.show()

14.

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
dim_num = 6
data = np.array([[0.40,0.32,0.35,0.30,0.30,0.88],
                 [0.85,0.35,0.30,0.40,0.40,0.30],
                 [0.43,0.89,0.30,0.28,0.22,0.30],
                 [0.30,0.25,0.48,0.85,0.45,0.40],
                 [0.20,0.38,0.87,0.45,0.32,0.28],
                 [0.34,0.31,0.38,0.40,0.92,0.28]])
angles = np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
angles = np.concatenate((angles, [angles[0]]))
data = np.concatenate((data, [data[0]]))
# 维度标签
radar_labels = ['研究型(I)','艺术型(A)','社会型(S)',
                '企业型(E)','传统型(C)','现实型(R)']
radar_labels = np.concatenate((radar_labels, [radar_labels[0]]))

plt.polar(angles, data)
#
plt.thetagrids(angles * 180/np.pi, labels=radar_labels)
#
plt.fill(angles, data,alpha=0.25)
plt.show()

15.

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family']='SimHei'
plt.rcParams['axes.unicode_minus']=False

x = np.arange(3)
y1 = np.array([2.04, 1.57, 1.63])
y2 = np.array([1.69, 1.61, 1.64])
y3 = np.array([4.65, 4.99, 4.94])
y4 = np.array([3.39, 2.33, 4.10])

error1 = [0.16, 0.08, 0.10]
error2 = [0.16, 0.08, 0.10]
error3 = [0.16, 0.08, 0.10]
error4 = [0.16, 0.08, 0.10]
bar_width = 0.2

plt.bar(x, y1, bar_width)
plt.bar(x + bar_width, y2, bar_width, align="center", tick_label=["春季", "夏季", "秋季"])
plt.bar(x + 2 * bar_width, y3, bar_width)
plt.bar(x + 3 * bar_width, y4, bar_width)

plt.errorbar(x, y1, yerr=error1, capsize=3, elinewidth=2, fmt='k,')
plt.errorbar(x + bar_width, y2, yerr=error2, capsize=3, elinewidth=2, fmt='k,')
plt.errorbar(x + 2 * bar_width, y3, yerr=error3, capsize=3, elinewidth=3, fmt='k,')
plt.errorbar(x + 3 * bar_width, y4, yerr=error4, capsize=4, elinewidth=3, fmt='k,')
plt.show()
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值