使用matplotlib绘制折线图

# matplotlib中文网 https://www.matplotlib.org
 
# 需求一:绘制某股票一周内收盘价折线图(见运行结果展示图)
 
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
 
# 0.设置中文黑体
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
 
# 1.准备数据
x_data = np.arange(1,8,1)
y_data = [44.98, 45.02, 44.32, 41.05, 42.08, 42.08, 42.08] # 周末休市
 
# 2.创建画布和坐标系
fig=plt.figure()
ax = fig.add_axes((0.2,0.2,0.5,0.5))
 
 
# 3.绘图
ax.plot(x_data, y_data, 'm-o',color='green', markersize='10')
 
# 4.定制刻度  方向朝内,宽度为2,长度为8,标签旋转角度
ax.tick_params(direction = 'in',width = 2,length = 8,labelrotation = 45)
 
# 5.设置轴标签
ax.set_xlabel('周日期')
ax.set_ylabel('收盘价')
ax.set_xticklabels(['周一', '周二', '周三', '周四', '周五', '周六', '周日'])
 # 6.隐藏上轴脊和右轴脊
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# # 7.展示图表
plt.show()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值