python用matplotlib画五角星_绘图:Matplotlib
用于绘制一些数据图,同学推荐的,挺好用。非常好的官网文档:http://matplotlib.org/contents.html
0. 安装
可以直接pip install,还有一些依赖就按照提示来吧,具体也忘了。
1. 基本画图
importmatplotlib.pyplot as plt
xs= [1,2,3,4]
ys= [1,2,3,4]
plt.plot(xs, ys)
plt.show()
xs表示点的x坐标,ys表示点的y坐标,所画的点就是(xs[i], ys[i]),默认情况下会依次用直线把点连起来。此时可以看到弹出一张过原点斜率为1的直线。注意show过后,不能再次show了,需要再plot画一次。说明这个plot模块是有状态的。
2. 散点
可以设置画图点的模式(markers),不使用直线将点连起来,而就是画个散点即可:
importmatplotlib.pyplot as plt
xs= [1,2,3,4]
ys= [1,2,3,4]
plt.plot(xs, ys, "ob");
plt.show()
此时看到的就是几个离散的点。这里"ob"表示使用圆形的marker并且颜色是蓝色(blue),其中filled_markers可以是:
'o' - 圆点, 'v' - 倒三角, '^' - 正三角, '<' - 左三角, '>' - 右三角, '8', 's' - 正方形, 'p' - 凸五边形, '*' - 五角星, 'h', 'H', 'D' - 菱形, 'd' - 扁菱形
All possible markers are defined here:
markerdescription
”.”
point
”,”
pixel
“o”
circle
“v”
triangle_down
“^”
triangle_up
“<”
triangle_left
“>”
triangle_right
“1”
tri_down
“2”
tri_up
“3”
tri_left
“4”
tri_right
“8”
octagon
“s”
square
“p”
pentagon
“*”
star
“h”
hexagon1
“H”
hexagon2
“+”
plus
“x”
x
“D”
diamond
“d”
thin_diamond
“|”
vline
“_”
hline
TICKLEFT
tickleft
TICKRIGHT
tickright
TICKUP
tickup
TICKDOWN
tickdown
CARETLEFT
caretleft
CARETRIGHT
caretright
CARETUP
caretup
CARETDOWN
caretdown
“None”
nothing
None
nothing
” “
nothing
“”
nothing
'$...$'
render the string using mathtext.
verts
a list of (x, y) pairs used for Path vertices. The center of the marker is located at (0,0) and the size is normalized.
path
a Path instance.
(numsides, style, angle)
see below
http://matplotlib.org/api/markers_api.html#module-matplotlib.markers
3.填充数据
可以结合numpy来快速的填充数据,画出图形
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x=np.arange(0, 4, 0.05)>>>x
array([ 0. ,0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4,0.45, 0.5 , 0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85,0.9 , 0.95, 1. , 1.05, 1.1 , 1.15, 1.2 , 1.25, 1.3,1.35, 1.4 , 1.45, 1.5 , 1.55, 1.6 , 1.65, 1.7 , 1.75,1.8 , 1.85, 1.9 , 1.95, 2. , 2.05, 2.1 , 2.15, 2.2,2.25, 2.3 , 2.35, 2.4 , 2.45, 2.5 , 2.55, 2.6 , 2.65,2.7 , 2.75, 2.8 , 2.85, 2.9 , 2.95, 3. , 3.05, 3.1,3.15, 3.2 , 3.25, 3.3 , 3.35, 3.4 , 3.45, 3.5 , 3.55,3.6 , 3.65, 3.7 , 3.75, 3.8 , 3.85, 3.9 , 3.95])>>> plt.plot(x, np.sin(0.5 * np.pi *x))
[]>>> plt.show()
4. 线条样式
Controlling line properties
Lines have many attributes that you can set: linewidth, dash style, antialiased, etc; see matplotlib.lines.Line2D. There are several ways to set line properties
Use keyword args:
plt.plot(x, y, linewidth=2.0)
Use the setter methods of the Line2D instance. plot returns a list of lines; e.g., line1, line2 = plot(x1,y1,x2,y2). Below I have only one line so it is a list of length 1. I use tuple unpacking in the line, = plot(x, y, 'o') to get the first element of the list:
line, = plt.plot(x, y, '-')
line.set_antialiased(False) # turn off antialising
Use the setp() command. The example below uses a MATLAB-style command to set multiple properties on a list of lines. setpworks transparently with a list of objects or a single object. You can either use python keyword arguments or MATLAB-style string/value pairs:
lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)
# or MATLAB style string value pairs
plt.setp(lines, 'color', 'r', 'linewidth', 2.0)
Here are the available Line2D properties.
PropertyValue Type
alpha
float
animated
[True | False]
antialiased or aa
[True | False]
clip_box
a matplotlib.transform.Bbox instance
clip_on
[True | False]
clip_path
a Path instance and a Transform instance, a Patch
color or c
any matplotlib color
contains
the hit testing function
dash_capstyle
['butt' | 'round' | 'projecting']
dash_joinstyle
['miter' | 'round' | 'bevel']
dashes
sequence of on/off ink in points
data
(np.array xdata, np.array ydata)
figure
a matplotlib.figure.Figure instance
label
any string
linestyle or ls
[ '-' | '--' | '-.' | ':' | 'steps' | ...]
linewidth or lw
float value in points
lod
[True | False]
marker
[ '+' | ',' | '.' | '1' | '2' | '3' | '4' ]
markeredgecolor or mec
any matplotlib color
markeredgewidth or mew
float value in points
markerfacecolor or mfc
any matplotlib color
markersize or ms
float
markevery
[ None | integer | (startind, stride) ]
picker
used in interactive line selection
pickradius
the line pick selection radius
solid_capstyle
['butt' | 'round' | 'projecting']
solid_joinstyle
['miter' | 'round' | 'bevel']
transform
a matplotlib.transforms.Transform instance
visible
[True | False]
xdata
np.array
ydata
np.array
zorder
any number
python用matplotlib画五角星_绘图:Matplotlib相关推荐
- python用matplotlib画五角星_基于Matplotlib的Python绘图
# 使用该法,不用写plt.show(),以及可以边写边运行 %matplotlib notebook import matplotlib.pyplot as plt plt.rcParams['fo ...
- 如何用python的turtle画五角星_海龟编辑器五角星怎么画 绘制五角星就是这么简单...
海龟编辑器作为一款面向少儿的Python编辑器,它可以让孩子通过图形化的方式学习Python,很多用户在刚开始使用时不知道怎么绘制最基本的图形,小编将绘制五角星的方式通过两种方法进行讲解,想知道的赶快 ...
- python 画八角形步骤_只需45秒,Python给故宫画一组手绘图!
原标题:只需45秒,Python给故宫画一组手绘图! 作者 |丁彦军 来源 |恋习Python(ID:sldata2017) 13日早晨,当北京市民拉开窗帘时发现,窗外雪花纷纷扬扬在空中飘落,而且越下 ...
- python用matplotlib画球_用Python的Matplotlib 画一个足球场
我们可能想要在图表上绘制线条或圆圈的原因有很多. 我们可以寻找添加平均线,突出显示关键数据点甚至绘制图片. 本文将展示如何使用足球场地图的示例添加线条,圆圈和圆弧,然后可以使用它来显示热图,传球或比赛 ...
- python 3d绘图 拖动_在python中以交互方式旋转3D绘图 - matplotlib
我想知道如何以this视频中描述的方式交互式旋转3D绘图(如果您从上方或下方或从右侧或左侧决定).我可以在spyder或jupyter Notebook中生成3D绘图,但之后它仍然是静态的,我无法与它 ...
- python 在图像上画线_在matplotlib中的图像上绘制网格线
您将需要安装 python成像库(PIL). (见 https://pypi.python.org/pypi/PIL).有关安装PIL: answer 1, answer 2的方法的示例,请参阅这些答 ...
- python下载matplotlib.finance模块_关于Matplotlib中No module named 'matplotlib.finance'的解决办法...
最近在研究量化分析,需要用到matplotlib中的一个库,输入 from matplotlib.finance import quotes_historical_yahoo_ohlc, candle ...
- python做动画的库_用matplotlib动画库制作等分法动画
经过反复试验,我找到了解决问题的办法.在import matplotlib.pyplot as plt from matplotlib import animation import numpy as ...
- 玩转Python之Turtle画五角星
Turtle库是Python语言中一个很流行的绘制图像的函数库,下面就给大家分享用Turtle画五角星: #coding=utf-8 import turtle import time turtle. ...
最新文章
- CSS 魔法系列:纯 CSS 绘制基本图形(圆、椭圆等)
- hdu 1806线段树 区间合并
- r语言没有forecast这个函数_R语言学习日记——时间序列分析之ARIMA模型预测
- Javascript实现的2048
- linux mint图标大小,Cinnamon:LinuxMint 15桌面设置小技巧
- .bash_profile和.bashrc说明
- win10下JDK环境变量配置与IDEA开发工具清晰简洁步骤,迈出Java学习第一步
- oracle 学习第一天
- python 获取照片拍摄时间_Python实现获取照片拍摄日期并重命名的方法
- 车载语音识别问题多 车主都说不靠谱
- Eclipse 导入项目与 svn 插件关联全过程记录
- python socket编程详细教程_最基础的Python的socket编程入门教程
- 接口耗时优化与cpu飙高解决
- 或再被“转手”,家乐福中国还能“攀”上哪座靠山?
- 军队文职(数学2+物理)——高等数学 1、函数
- 2020支付行业七大预测:聚合支付牌照有望正式落地
- java 自动转 golang_JAVA转Golang
- Jekins的简介和使用
- android 严振杰权限管理,MyAndroidFrameWork
- Access denied for user ‘user‘@‘%‘ to database 可能的原因