python 画图 图例自由定义方式


Posted in Python onApril 17, 2020

我就废话不多说了,还是直接看代码吧!

# -*- coding: utf-8 -*-
"""
Created on Wed Mar 7 13:10:21 2018
 
@author: su
"""
 
import numpy as np
import matplotlib.pyplot as plt 
 
n_groups = 2
 
num_list = [0.8,0.80] 
num_list1 = [0.8,0.8] 
num_list2 = [0.9,0.9] 
num_list3 = [0.9,0.9] 
fig, ax = plt.subplots()
plt.grid(True, linestyle = "-", color = "#9dbcd4", linewidth = "0.7",axis= 'y') 
ax = plt.gca()
ax.spines['top'].set_visible(False) #去掉上边框
ax.spines['right'].set_visible(False) #去掉右边框
ax.spines['bottom'].set_visible(False) #去掉上边框
ax.spines['left'].set_visible(False) #去掉右边框
ax.tick_params(axis='y',width=0,length=0)
ax.tick_params(axis='x',width=0,length=0)
index = np.arange(n_groups)
bar_width = 0.5
opacity = 1
rects1 = plt.bar(index, num_list, bar_width/4,alpha=opacity, color='#6B7C85',label='Logistic',hatch='')
rects2 = plt.bar(index + bar_width/4, num_list1, bar_width/4,alpha=opacity,color='#9dbcd4',label='SVM',hatch='/')
rects3= plt.bar(index + bar_width/2, num_list2, bar_width/4,alpha=opacity,color='#1f3d4b',label='CNN',hatch='-')
rects4= plt.bar(index + bar_width*3/4, num_list3, bar_width/4,alpha=opacity,color='#3f829d',label='LSTM',hatch=':')   
# plt.xlabel('Group')
plt.ylabel('Accuracy', fontsize=18)
# plt.title('Scores by group and gender')
plt.xticks(index - 0.3+ bar_width, ('Chinese', 'English'),fontsize =18) 
plt.yticks(fontsize =18) #change the num axis size 
plt.ylim(0.7,0.95) #The ceil 
# 设置legend
plt.legend(loc='center', bbox_to_anchor=(0.5,-0.2),ncol=4,frameon=False,shadow=False)
plt.tight_layout() 
plt.show()

python 画图 图例自由定义方式

去除边框,图例放图下面。设置横标线

以上这篇python 画图 图例自由定义方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python写的ARP攻击代码实例
Jun 04 Python
Python求解平方根的方法
Mar 11 Python
Python与shell的3种交互方式介绍
Apr 11 Python
Python中实现三目运算的方法
Jun 21 Python
详解Python操作RabbitMQ服务器消息队列的远程结果返回
Jun 30 Python
Python生成密码库功能示例
May 23 Python
python @propert装饰器使用方法原理解析
Dec 25 Python
PyQt5 文本输入框自动补全QLineEdit的实现示例
May 13 Python
python 解决Fatal error in launcher:错误问题
May 21 Python
Python高阶函数与装饰器函数的深入讲解
Nov 10 Python
Python爬虫之Selenium设置元素等待的方法
Dec 04 Python
Python干货实战之八音符酱小游戏全过程详解
Oct 24 Python
关于python 的legend图例,参数使用说明
Apr 17 #Python
python 实现仿微信聊天时间格式化显示的代码
Apr 17 #Python
python matplotlib实现将图例放在图外
Apr 17 #Python
python 比较字典value的最大值的几种方法
Apr 17 #Python
Python3 selenium 实现QQ群接龙自动化功能
Apr 17 #Python
python plt可视化——打印特殊符号和制作图例代码
Apr 17 #Python
Python 多线程共享变量的实现示例
Apr 17 #Python
You might like
刷新PHP缓冲区为你的站点加速
2015/10/10 PHP
PHP+iframe图片上传实现即时刷新效果
2016/11/18 PHP
Yii1.1中通过Sql查询进行的分页操作方法
2017/03/16 PHP
Thinkphp5 如何隐藏入口文件index.php(URL重写)
2019/10/16 PHP
Prototype Number对象 学习
2009/07/19 Javascript
Iframe 自适应高度并实时监控高度变化的js代码
2009/10/30 Javascript
jquery中的ajax方法怎样通过JSONP进行远程调用
2014/05/04 Javascript
javascript实现在某个元素上阻止鼠标右键事件的方法和实例
2014/08/12 Javascript
Python脚本后台运行的几种方式
2015/03/09 Javascript
jQuery实现元素拖拽并cookie保存顺序的方法
2016/02/20 Javascript
Zabbix添加Node.js监控的方法
2016/10/20 Javascript
用jQuery的AJax实现异步访问、异步加载
2016/11/02 Javascript
jsTree使用记录实例
2016/12/01 Javascript
AngularJS基于ui-route实现深层路由的方法【路由嵌套】
2016/12/14 Javascript
非常实用的vue导航钩子
2017/03/20 Javascript
AngularJS中的promise用法分析
2017/05/19 Javascript
在Vue中使用echarts的方法
2018/02/05 Javascript
JavaScript事件冒泡机制原理实例解析
2020/01/14 Javascript
vue键盘事件点击事件加native操作
2020/07/27 Javascript
Django中传递参数到URLconf的视图函数中的方法
2015/07/18 Python
简单讲解Python编程中namedtuple类的用法
2016/06/21 Python
Python中标准模块importlib详解
2017/04/16 Python
numpy中实现二维数组按照某列、某行排序的方法
2018/04/04 Python
对Python信号处理模块signal详解
2019/01/09 Python
dataframe 按条件替换某一列中的值方法
2019/01/29 Python
python爬虫今日热榜数据到txt文件的源码
2021/02/23 Python
纯css3实现的鼠标悬停动画按钮
2014/12/23 HTML / CSS
校园学雷锋活动月总结
2014/03/09 职场文书
师范生自荐信模板
2014/05/28 职场文书
本科毕业生应聘求职信
2014/07/06 职场文书
个人查摆剖析材料
2014/10/04 职场文书
2014年建筑工作总结
2014/11/26 职场文书
工作违纪检讨书范文
2015/01/26 职场文书
社区禁毒宣传活动总结
2015/05/07 职场文书
2015年小班保育员工作总结
2015/05/27 职场文书
2021年最新用于图像处理的Python库总结
2021/06/15 Python