python应用-matplotlib绘图
详细内容参看:官网
测试数据:
# 传入的参数
x=[1,2,3,4,5]
squares=[1,4,9,16,25]
简单的绘图
import matplotlib.pyplot as plt
def plot1(x,squares):
"""plot simple pic"""
plt.plot(x,squares,linewidth=1)
# or plt.plot(squares)
plt.show()
- plt.plot(x,y)
- plt.show()
改变文字、字体、线宽
def plot2(x,squares):
"""change literature and line width"""
plt.plot(x,squares,linewidth=2)
plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14)
# set labelsize of x, y
plt.tick_params(axis='both',labelsize=14)
plt.show()
- plt.title("title")
- plt.xlabel('xlabel')
- plt.ylabel('ylabel')
- plt.tick_params(axis,labelsize)
自动生成数据
def plot3():
"""automatically compute the data"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val]
plt.scatter(x_val,y_val,s=5)
plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14)
# set labelsize of x, y
plt.tick_params(axis='both',labelsize=14)
plt.axis([0,1100,0,1100000])
plt.show()
- plt.axis([0,1100,0,110000])
- plt.scatter(x,y,s)
颜色改变(很漂亮)

def plot4():
"""change the color"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val]
# delete the default edgecolor(black)
# change color by adjusting c
plt.scatter(x_val,y_val,edgecolor='none',c=(0.5,0.6,0.3),s=5)
plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14)
# set labelsize of x, y
plt.tick_params(axis='both',labelsize=14)
plt.axis([0,1100,0,1100000])
plt.show()
- plt.scatter(x,y,edgecolor='none',c,s)
- c用来调节颜色
- s代表size
def plot5():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val]
# delete the default edgecolor(black)
# using cmap to make gradient
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.Blues)
plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14)
# set labelsize of x, y
plt.tick_params(axis='both',labelsize=14)
plt.axis([0,1100,0,1100000])
plt.show()
- plt.scatter(x,y,edgecolor,c,s,cmap)
- cmap颜色映射
- plt.cm.Blues
- plt.cm.Reds
- plt.cm.Greens
- plt.cm.Paired
- plt.cm.binary
- plt.cm.seismic
- cmap颜色映射
保存图片
def plot6():
"""using colormap"""
x_val = list(range(1,1001))
y_val = [x**2 for x in x_val]
# delete the default edgecolor(black)
# using cmap to make gradient
# cmap(plt.cm.*) Blues Reds Greens Paired binary seismic
plt.scatter(x_val,y_val,edgecolor='none',c=y_val,s=5,cmap=plt.cm.seismic)
plt.title("Literatures",fontsize=24)
plt.xlabel("xlabel",fontsize=14)
plt.ylabel("ylabel",fontsize=14)
# set labelsize of x, y
plt.tick_params(axis='both',labelsize=14)
plt.axis([0,1100,0,1100000])
# do not show, save it
plt.savefig('save.png',bbox_inches='tight')
- plt.savefig('name.jpg',bbox_inches)
- 一般bbox_inches='tight'比较好
python应用-matplotlib绘图的更多相关文章
- python 中matplotlib 绘图
python 中matplotlib 绘图 数学建模需要,对于绘图进行简单学习 matpoltlib之类的包安装建议之间用anaconda 绘制一条y=x^2的曲线 #比如我们要绘制一条y=x^2的曲 ...
- python之matplotlib绘图基础
Python之matplotlib基础 matplotlib是Python优秀的数据可视化第三方库 matplotlib库的效果可参考 http://matplotlib.org/gallery.ht ...
- python基于matplotlib绘图
import math import numpy as np import matplotlib.pyplot as plt from matplotlib.font_manager import F ...
- python中matplotlib绘图封装类之折线图、条状图、圆饼图
DrawHelper.py封装类源码: import matplotlib import matplotlib.pyplot as plt import numpy as np class DrawH ...
- Python用matplotlib绘图网格线的设置
一.X轴网格线的设置 import matplotlib.pyplot as plt import numpy as np from pylab import mpl mpl.rcParams['fo ...
- python中利用matplotlib绘图可视化知识归纳
python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...
- python 利用matplotlib中imshow()函数绘图
matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中.通过简单的绘图语 ...
- python实战学习之matplotlib绘图
matplotlib 是最流行的Python底层绘图库,主要做数据可视化图表 可以将数据可视化,能够更直观的呈现数据 matplotlib绘图基本要点 首先实现一个简单的绘图 # 导入pyplot f ...
- python强大的绘图模块matplotlib示例讲解
Matplotlib 是 Python 的绘图库.作为程序员,经常需要进行绘图,在我自己的工作中,如果需要绘图,一般都是将数据导入到excel中,然后通过excel生成图表,这样操作起来还是比较繁琐的 ...
随机推荐
- thinkphp --- 写入日志
在开发过程中,对于一些参数,不好直接输入或者打印调试,特别是在微信开发过程中,这个时候,通过日志来查看信息就显得格外重要. 下面是在TP3.2.3框架中,写入日志的方法: public functio ...
- Dij二级最短路
hdu1245 Saving James Bond Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- mycelipse中关于编码的配置
(1)修改工作空间的编码方式: Window->Preferences->General->Workspace->Text file Encoding在Others里选择需要的 ...
- 前端模拟(mock)接口数据(koa)
在前后端分离开发项目时,经常会有前后端进度不一致,可能前端界面开发已经完成,就等接口了,如果等接口出来再联调的话时间可能会来不及. 这个时候,前端就可以根据制定好的接口规范和接口文档来mock接口数据 ...
- Kafka Consumer接口
对于kafka的consumer接口,提供两种版本, high-level 一种high-level版本,比较简单不用关心offset, 会自动的读zookeeper中该Consumer grou ...
- Python爬虫基础(四)Requests库的使用
requests文档 首先需要安装:pip install requests get请求 最基本的get: # -*- coding: utf-8 -*-import requests respons ...
- Mirror--镜像断开的解决办法
如果镜像在搭建一段时候后出现问题,可能存在以下原因: 1. 因为主库或镜像库存在内存压力,导致无法完成镜像日志传送和重做 解决办法:设置数据库最小内存,保证数据库有足够内存完成镜像操作 2. 因为主库 ...
- Android仿今日头条手界面
public class MyIndicator extends HorizontalScrollView implements ViewPager.OnPageChangeListener { pr ...
- 整数(质因子)分解(Pollard rho大整数分解)
整数分解,又称质因子分解.在数学中,整数分解问题是指:给出一个正整数,将其写成几个素数的乘积的形式. (每个合数都可以写成几个质数相乘的形式,这几个质数就都叫做这个合数的质因数.) .试除法(适用于范 ...
- Web Services 简介
通过使用 Web Services,您的应用程序可以向全世界发布信息,或提供某项功能.Web Services 脚本平台需支持 XML + HTTP. Web Services 简介 Web Serv ...