数据可视化之折线图plot

import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['SimHei']

查看matplotlibde文件地址

import matplotlib

print(matplotlib.matplotlib_fname())

plt.rcParams['font.sans-serif'] = ['SimHei']

准备数据

time = ['20200401','20200402','20200403','20200404','20200405']
china = [93,78,73,55,75]
usa = [18697,28599,32309,34444,19236]

创建画布

plt.figure()

绘制折线图

marker 标记点,可以是o,.v^<>*-|

markersize 标记点大小

mec 标记点边框颜色 markeredgecolo

mfc 标记点内部颜色 markerfacecolor

linestyle 线的样式

label起名---->xlabel,ylabel

linewidth ---> lw 线的宽度

plt.plot(time,china,marker = '*',markersize = 20,mec= 'b',mfc = 'k',color ='y',label='中国')
plt.plot(time,usa,marker = 'o',linestyle ='-',linewidth = 5,color ='r',label='美国')

添加辅助显示层

添加x,y轴刻度

由于数据不同,需要传入数据一一对应

xticks = ['4月1日','4月2日','4月3日','4月4日','4月5日']
plt.xticks(time,xticks)
#准备刻度的数据

yticks=range(0,101,10) # 添加一个整数列表,

range(start,stop,step)

数据类型一致,可以直接显示

plt.yticks(yticks)

添加x轴名称,可以设置为: 'left', 'right', 和 'center', 默认值为 'center'。

plt.xlabel('日期',loc='left')

添加y轴名称,可以设置为: 'bottom', 'top', 和 'center', 默认值为 'center'.

plt.ylabel('人数',loc='top')

设置标题,可以设置为: 'left', 'right', 和 'center', 默认值为 'center'。

plt.title('新增人数',loc='center')

添加图例

plt.legend()

显示网格线,

true/false第一个参数表示是否显示网格线,默认true,可以不写

linestyle 第二个参数表示网格线的样式

alpha 第三个参数表示网格线的透明度,范围是0-1,1表示不透明,0表示透明

axis 第四个设置显示哪个方向的网格线

color,linstyle,linewidth....同样的在网格线的设置中也可以设置线的颜色,样式,宽度。。。。

plt.grid(True,linestyle='--',alpha=0.5,axis='y')

展示

plt.show(block=True)

相关推荐
SelectDB4 小时前
岚图汽车 x Apache Doris : 海量车联网数据实时分析实践
数据分析·github·数据可视化
杨超越luckly9 小时前
HTML应用指南:利用GET请求获取全国中国建设银行网点位置信息
前端·arcgis·html·数据可视化·门店数据
eqwaak012 小时前
动态图表导出与视频生成:精通Matplotlib Animation与FFmpeg
开发语言·python·ffmpeg·音视频·matplotlib
MoRanzhi12031 天前
15. Pandas 综合实战案例(零售数据分析)
数据结构·python·数据挖掘·数据分析·pandas·matplotlib·零售
数字冰雹1 天前
图观 流渲染打包服务器
服务器·前端·github·数据可视化
拜无忧1 天前
【案例】可视化模板,驾驶舱模板,3x3,兼容移动
前端·echarts·数据可视化
Love__Tay2 天前
【数据分析与可视化】2025年一季度金融业主要行业资产、负债、权益结构与增速对比
金融·excel·pandas·matplotlib
weixin_525936334 天前
金融大数据处理与分析
hadoop·python·hdfs·金融·数据分析·spark·matplotlib
风遥~4 天前
快速了解并使用Matplotlib库
人工智能·python·数据分析·matplotlib
VincentFHR8 天前
Canvas 高性能K线图,支持无限左右滑动
前端·数据可视化·canvas