py matplotlib 多个figure同时画多个图以及多个图例多个折线图
图例负号乱码的问题
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
需要读取数据模板文件,格式如下,首先是后续要显示的名称,然后是成本价、净值,使用【/】分隔
建信50 | 0.8502/0.8499/0.8496 | 0.8263/0.8239/0.8253 | 0.0260/0.0246
富国中正红利 | 1.1273/1.1270/1.1263 | 1.1030/1.1040/1.0960 | 0.0230/0.0310
景顺中正500 | 0.9798/0.9792/0.9780 | 0.9271/0.9250/0.9149 | 0.0542/0.0643
前海开源人工智能 | 1.0665/1.0653/1.0625 |0.9930/0.9890/0.9870 | 0.0763
易方达创业板 | 1.6463/1.6452/1.6434 | 1.5368/1.5377/1.5233 | 0.1075
南方价值混合C|1.0843/1.0837/1.0819 | 1.0520/1.0520/1.0490 | 0.0317
# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib font = {
'family' : 'SimHei'
}
matplotlib.rc('font', **font) ["","NFYXJZHHC","南方优选价值混合C","混合型","NANFANGYOUXUANJIAZHIHUNHEC"]
["","FGZZHLZSZQ","富国中证红利指数增强","股票指数","FUGUOZHONGZHENGHONGLIZHISHUZENGQIANG"]
["","JSZZ500HYZXDBD","景顺中证500行业中性低波动","股票指数","JINGSHUNZHONGZHENG500HANGYEZHONGXINGDIBODONG"]
["","QHKYRGZNZTHH","前海开源人工智能主题混合","混合型","QIANHAIKAIYUANRENGONGZHINENGZHUTIHUNHE"]
["","YFDCYBETFLJC","易方达创业板ETF联接C","联接基金","YIFANGDACHUANGYEBANETFLIANJIEC"]
["","JXYS50","建信央视50","股票指数","JIANXINYANGSHI50"]
i=1
index=321
subIndex=321
def calc(value):
global index
day="6-1,6-2,6-3".split(',')
#v="建信50 | 0.8502/0.8499/0.8496 | 0.8263/0.8239/0.8253 | 0.0260/0.0246".split('|')
v=value.split('|')
name=v[0]
myValue=[]
for m in v[1].split('/'):
myValue.append(float(m))
curValue=[]
for m in v[2].split('/'):
curValue.append(float(m))
z=[]
#整理差值数据
for i in range(len(day)):
z.append((myValue[i]-curValue[i])*10) plt.figure(1)
plt.subplot(index)
plt.plot(day, myValue, color = 'blue', linewidth = 2.0, linestyle = '-',label="持仓成本价")
plt.plot(day, curValue, color = 'red', linewidth = 2.0, linestyle = '--',label="当前净值")
plt.legend() #显示上面的label
plt.title(name) #添加标题 plt.figure(2)
plt.subplot(index)
plt.plot(day, z, color = 'red', linewidth = 2.0, linestyle = '-',label="差值")
plt.legend() #显示上面的label
plt.title(name+"差值") #添加标题
index=index+1
return z def sub(name,value):
plt.figure(1)
plt.subplot(index)
index=index+1 plt.plot(day, value, color = 'red', linewidth = 2.0, linestyle = '-',label="差值")
plt.legend() #显示上面的label
plt.title(name+"差值") #添加标题 with open("./a.txt",'r', encoding='UTF-8') as file:
for line in file:
z=calc(line)
name=(line.split('|'))[0]
#print(name)
plt.show()
py matplotlib 多个figure同时画多个图以及多个图例多个折线图的更多相关文章
- matplotlib的使用--折线图--入门
目录 matplotlib应用介绍 一天天气变化图 两小时随机温度图 中文显示问题 个人交往统计图 多人交往统计图 总结 介绍: 举个例子(一天天气变化图): 假设一天中每隔两个小时(range(2, ...
- python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)
最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指 ...
- 用matplotlib.pyplot画简单的折线图,直方图,散点图
#coding=utf-8 """ 用matplotlib.pyplot画简单的折线图,直方图,散点图 """ import matplot ...
- Matplotlib学习---用matplotlib画折线图(line chart)
这里利用Jake Vanderplas所著的<Python数据科学手册>一书中的数据,学习画图. 数据地址:https://raw.githubusercontent.com/jakevd ...
- Matplotlib中plot画点图和折线图
引入: import matplotlib.pyplot as plt 基本语法: plt.plot(x, y, format_string, **kwargs) x:x轴数据,列表或数组,可选 y: ...
- python用matplotlib画折线图
折线图: import matplotlib.pyplot as plt y1=[10,13,5,40,30,60,70,12,55,25] x1=range(0,10) x2=range(0,10) ...
- 06. Matplotlib 2 |折线图| 柱状图| 堆叠图| 面积图| 填图| 饼图| 直方图| 散点图| 极坐标| 图箱型图
1.基本图表绘制 plt.plot() 图表类别:线形图.柱状图.密度图,以横纵坐标两个维度为主同时可延展出多种其他图表样式 plt.plot(kind='line', ax=None, figsiz ...
- Python开发【模块】:matplotlib 绘制折线图
matplotlib 1.安装matplotlib ① linux系统安装 # 安装matplotlib模块 $ sudo apt-get install python3-matplotlib # 如 ...
- python中matplotlib绘图封装类之折线图、条状图、圆饼图
DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...
随机推荐
- mmu(虚拟地址和物理地址简单图解)
- 浅入深出Vue:文章编辑
登录与注册功能都已经实现,现在是时候来开发文章编辑功能了. 这里咱们就使用 markdown 作为编辑语言吧,简洁通用.那么我们就需要找一下 markdown 的编辑器组件了,而且还要支持 vue噢. ...
- 集成学习的不二法门bagging、boosting和三大法宝<结合策略>平均法,投票法和学习法(stacking)
单个学习器要么容易欠拟合要么容易过拟合,为了获得泛化性能优良的学习器,可以训练多个个体学习器,通过一定的结合策略,最终形成一个强学习器.这种集成多个个体学习器的方法称为集成学习(ensemble le ...
- Hadoop-No.7之行键
和哈希表类比,HBase中的行键类似于哈希表中的键.要构造一个良好的HBase模式,关键之一就是选择一个合适的行键. 1 记录检索 行键是HBase中检索记录所使用的键.HBase记录含有的列在数量上 ...
- hdu 6078 Wavel Sequence
题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6078 (2017 Multi-University Training Contest - Team ...
- C语言构建小型Web服务器
#include <stdio.h> #include <sys/socket.h> #include <stdlib.h> #include <string ...
- 4、路由事件 RoutedEvent
路由事件的类型:具体参考https://www.cnblogs.com/jellochen/p/3475754.html Tunnel隧道方式:路由事件使用隧道策略,以便事件实例通过树向下路由(从根到 ...
- mysql简单用法
来源:http://hi.baidu.com/demon119/item/e4917f30b6482949023edc33 mysql 用法 #mysql -uroot -proot //可直接登录m ...
- Dungeon Master (POJ - 2251)(BFS)
转载请注明出处: 作者:Mercury_Lc 地址:https://blog.csdn.net/Mercury_Lc/article/details/82693907 题目链接 题解:三维的bfs,一 ...
- ngx_http_auth_request_module 第三方认证
shell > vim /usr/local/nginx-1.10.2/conf/vhost/auth.conf # 这是第三方认证服务器,认证逻辑使用的 PHP 代码 server { lis ...