[入门]——matplotlib——条形图

matplotlib是第三方库中一个绘图的库。

# -*- coding: utf-8 -*-
"""


matplotlib 库的学习
matplotlib 是一个绘图库,他可以创建常用的统计图,包括条形图、箱线图、折线图、散点图和直方图


"""

"""
条形图

"""

import matplotlib.pyplot as plt #导入

plt.style.use('ggplot') #设置样式, 模拟gglot2风格的绘图

customers = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO'] #客户名数据
customers_index = range(len(customers)) #生成客户索引序列
sale_amounts = [127, 90,201, 111, 232] #客户销售数量数据

fig = plt.figure() #创建基础图
ax1 = fig.add_subplot(1,1,1) #添加子图

ax1.bar(customers_index, sale_amounts, align='center', color='darkgreen') #创建条形图

ax1.xaxis.set_ticks_position('bottom') #设置x轴的刻度线位置
ax1.yaxis.set_ticks_position('left') #设置y轴的刻度线位置
plt.xticks(customers_index, customers, rotation=45, fontsize='small') #刻度线标签 更改为实际客户名
plt.xlabel('customer') #添加x轴标签
plt.ylabel('sale amount')# y轴标签
plt.title('sale amount per customer')# 添加标题
plt.savefig('bar_plot.png', dpi=400,bbox_inches='tight')# 保存设置  保存文件名, 图形分辨率, 保存图形时四周去空白

plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值