Python编程:从入门到实践 - matplotlib篇 - plot & scatter
matplotlib篇 plot & scatter
# filename.py 获取当前文件名方法
import sys # 当前文件名
print(sys.argv[0]) # 去除后缀后的文件名
print(sys.argv[0].split('.')[0])
# mpl_squares.py 简单的平方折线图
import matplotlib.pyplot as plt
import sys input_values = [x for x in range(1, 6)]
squares = [x ** 2 for x in range(1, 6)] # 函数plot尝试根据数字绘制除有意义的图形
# linewidth参数设置线条宽度
plt.plot(input_values, squares, linewidth=2) # 设置图标标题,并给坐标轴加上标签
plt.title('Square Numbers', fontsize=24)
plt.xlabel('Value', fontsize=14)
plt.ylabel('Square of Value', fontsize=14) # 设置刻度标记的大小
plt.tick_params(axis='both', labelsize=14) # 函数show打开matplotlib查看器,并显示出绘制的图形
# plt.show() plt.savefig('images/' + sys.argv[0].split('.')[0] + '.png', bbox_inches='tight')
# scatter_squares.py 使用scatter绘制散点图并设置其样式 import matplotlib.pyplot as plt
import sys x_values = [x for x in range(1, 101)]
y_values = [x ** 2 for x in range(1, 101)] # edgecolor参数 -- 点轮廓
# c参数 -- 点颜色(接受RGB值(必须是三个0~1之间的小数值组成的元组)或'red'等) 值越接近0,指定的颜色越深,值越接近1,指定的颜色越浅。
# s参数 -- 点大小
#plt.scatter(x_values, y_values, edgecolor='none', s=10, c=(0.4, 0.4, 0)) # 将c参数设置为y列表,并使用参数cmap告诉pyplot使用哪个颜色映射(渐变)
plt.scatter(x_values, y_values, c=y_values, cmap=plt.cm.Blues, edgecolor='none', s=10) # 设置图标标题并给坐标加上标签
plt.title('Squares Numbers', fontsize=24)
plt.xlabel('Value', fontsize=14)
plt.ylabel('Square of Value', fontsize=14) # 设置刻度标记的大小
plt.tick_params(axis='both', which='major', labelsize=14) # 自动保存图表
plt.savefig('images/' + sys.argv[0].split('.')[0] + '.png', bbox_inches='tight')
# 第一个实参指定要以什么样的文件名保存图表
# 第二个实参指定将图表多余的空白区域裁剪掉
# mpl_cubes 立方折线图 import matplotlib.pyplot as plt
import sys x_values = [x for x in range(1, 6)]
y_values = [y ** 3 for y in range(1, 6)] plt.plot(x_values, y_values, color='y', linestyle='--', linewidth=2) plt.xlabel('Cubes', fontsize=14)
plt.ylabel('Values', fontsize=14)
plt.title('Map for Cubes', fontsize=14) plt.tick_params(axis='both', labelsize=10) plt.savefig('images/' + sys.argv[0].split('.')[0] + '.png', bbox_inches='tight')
# scatter_cubes.py 立方散点图 import matplotlib.pyplot as plt
import sys x_values = [x for x in range(1, 101)]
y_values = [y ** 3 for y in range(1, 101)] plt.scatter(x_values, y_values, c=y_values, cmap=plt.cm.Reds, s=10, edgecolor='none') plt.xlabel('Values', fontsize=14)
plt.ylabel('Cubes', fontsize=14)
plt.title('Map for Cubes', fontsize=24) plt.tick_params(axis='both', labelsize=10) plt.savefig('images/' + sys.argv[0].split('.')[0] + '.png', bbox_inches='tight')
Python编程:从入门到实践 - matplotlib篇 - plot & scatter的更多相关文章
- 《Python编程:从入门到实践》分享下载
书籍信息 书名:<Python编程:从入门到实践> 原作名:Python Crash Course 作者: [美] 埃里克·马瑟斯 豆瓣评分:9.1分(2534人评价) 内容简介 本书是一 ...
- Python编程从入门到实践笔记——异常和存储数据
Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...
- Python编程从入门到实践笔记——文件
Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...
- Python编程从入门到实践笔记——类
Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...
- Python编程从入门到实践笔记——函数
Python编程从入门到实践笔记——函数 #coding=gbk #Python编程从入门到实践笔记——函数 #8.1定义函数 def 函数名(形参): # [缩进]注释+函数体 #1.向函数传递信息 ...
- Python编程从入门到实践笔记——用户输入和while循环
Python编程从入门到实践笔记——用户输入和while循环 #coding=utf-8 #函数input()让程序暂停运行,等待用户输入一些文本.得到用户的输入以后将其存储在一个变量中,方便后续使用 ...
- Python编程从入门到实践笔记——字典
Python编程从入门到实践笔记——字典 #coding=utf-8 #字典--放在{}中的键值对:跟json很像 #键和值之间用:分隔:键值对之间用,分隔 alien_0 = {'color':'g ...
- Python编程从入门到实践笔记——if语句
Python编程从入门到实践笔记——if语句 #coding=utf-8 cars=['bwm','audi','toyota','subaru','maserati'] bicycles = [&q ...
- Python编程从入门到实践笔记——操作列表
Python编程从入门到实践笔记——操作列表 #coding=utf-8 magicians = ['alice','david','carolina'] #遍历整个列表 for magician i ...
随机推荐
- ubuntu14.04上搭建android开发环境
这几天心血来潮,想在ubuntu上写写android软件.所以就上网找些资料在ubuntu上搭建android环境.结果要么时不完整的,要么就是过时的. 所以我把我搭建android环境的过程写下了, ...
- 11gR2 Database Services for "Policy" and "Administrator" Managed Databases (文档 ID 1481647.1)
In this Document Purpose _afrLoop=1459311711568804&id=1481647.1&displayIndex=6&_afrW ...
- Codeforces Beta Round #95 (Div. 2) D. Subway 边双联通+spfa
D. Subway A subway scheme, classic for all Berland cities is represented by a set of n stations co ...
- SQLite 常用函数
SQLite 常用函数 参考: SQLite 常用函数 | 菜鸟教程http://www.runoob.com/sqlite/sqlite-functions.html SQLite 常用函数 SQL ...
- k8s Gitlab CI/CD 之自动编译Docker镜像并推送到指定的Registry
环境介绍: 说明 节点 ip 系统 Gitlab Server git.ds.com 10.0.1.179 CentOS 7.5.1804 Gitlab Runner 10.0.1.178 Cen ...
- css3 animate写的超炫3D转换
上一篇中介绍了animate的基本的属性,这一篇讲的则是关于animate以及transforms的使用 <!DOCTYPE html><html lang="en&quo ...
- VM-安装MAC系统
搜了下论坛没有这个教程,继续搬运一波,这次教的是用VM15安装Mac OS10.14懒人版VMware安装Windows和Linux比较类似,相对于今天要安装的MAC OS来说过程也比较简单.官方原版 ...
- NOIP 2013 T2 火柴排队 ---->求逆序对
[NOIP2013T2]火柴排队 背景 noip2013day1 描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各 自 排成一列, 同一列火柴的高度互不相同, ...
- 查看 myeclipse激活状态
查看激活状态 myeclipse-->subscription information
- [hihicoder][Offer收割]编程练习赛47
删除树节点 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...