Matplotlib Scatter散点图用法总结-任务输出

需求描述:做出新能源汽车推广目录(19年第11批)纯电车型的分析

绘制乘用车总质量与工况电耗的散点图

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os

# 中文打印代码
font = {'family': 'SimHei',
        'weight': 'bold',
        'size': '8'}
plt.rc('font', **font)               # 步骤一(设置字体的更多属性)
plt.rc('axes', unicode_minus=False)  # 步骤二(解决坐标轴负数的负号显示问题)
#中文输出设置
data_path = 'D:/PythonFile/2020-01-25/chuli'

data_file = os.path.join(data_path, 'chengyongche.xlsx')
#路径设置
ReadData_Cheng = pd.read_excel(data_file)
#Excel文件读取函数
fig, ax = plt.subplots()
ax.scatter(ReadData_Cheng['总质量(kg)'],
           ReadData_Cheng['工况条件下百公里耗电量(Y)(kWh/100km)'], c='red', marker="o", alpha=0.6, s=50)
ax.set_xlabel('总质量(kg)', fontsize=10)#x轴坐标设置
ax.set_ylabel('况条件下百公里耗电量(kwh/100km)', fontsize=10)#y轴坐标设置
ax.set_title("总质量-百公里电耗曲线", fontsize=15)#title设置
ax.legend(loc=0, fontsize=8)#图例设置
ax.grid(True)#网格设置
x0, y0 = ReadData_Cheng.iloc[21, 4], ReadData_Cheng.iloc[21, 3]
x1, y1 = ReadData_Cheng.iloc[6, 4], ReadData_Cheng.iloc[6, 3]
x2, y2 = ReadData_Cheng.iloc[2, 4], ReadData_Cheng.iloc[2, 3]
ax.annotate('特斯拉牌', xy=(x0, y0), xytext=(
    x0, y0-1), arrowprops=dict(arrowstyle='->'), color='k', fontsize=12)
ax.annotate('威马EX5', xy=(x1, y1), arrowprops=dict(arrowstyle='->'), xytext=(
    x1, y1+0.5),  color='k', fontsize=12)
ax.annotate('长城欧拉', xy=(x2, y2), xytext=(
    x2, y2+0.5), arrowprops=dict(arrowstyle='->'), color='k', fontsize=12) 
#设置描述点
plt.xticks(range(1000, 3000, 200))#网格大小设置
fig.tight_layout()#用于输出图位置自动调整
plt.show()

输出结果:
绘制总质量与工况百公里电耗曲线
涉及知识点:
1、散点图scatter()函数用法。
2、图例、XY坐标、图标、识别点等用法。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值