用python绘制图形的一些使用技巧
2016-12-02 17:15
771 查看
1.颜色(color):
八种内建的颜色缩写
b : blue
g : green
r : red
c : cyan
m : magenta
y : yellow
k : block
w : white
其他的颜色表示方法
(1).灰色阴影(通过数值来设置)
(2).html中最常见的十六进制表示
(3).RGB元组
示例如下:
对于下面三种对颜色的设置,可以通过百度轻轻松松获取到,直接搜索颜色代码就可以,会提示很多,随便选一个自己认为合适的就可以。
2.点(marker)的样式(共有23种)
3.线的样式
线共有四种样式, 不需要显示指定
- 实线
-- 虚线
-. 点划线
: 点线
4.样式字符串
可以将颜色,点型,线型写成一个字符串(颜色只能是内建的8种颜色类型的一种,不能是后面提到的那三种情况,测试结果是这样的)
#!/usr/bin/python
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
plt.plot(x, "g8:")
plt.plot(x + 1, "b4--")
plt.plot(x + 2, "cH-.")
plt.plot(x + 3, "kH-")
plt.show()
八种内建的颜色缩写
b : blue
g : green
r : red
c : cyan
m : magenta
y : yellow
k : block
w : white
其他的颜色表示方法
(1).灰色阴影(通过数值来设置)
(2).html中最常见的十六进制表示
(3).RGB元组
示例如下:
#!/usr/bin/python #coding: utf-8 import numpy as np import matplotlib.pyplot as plt x = np.arange(10) # 使用内建的方法 plt.plot(x, color = "g") # 使用灰色阴影(通过数值指定) plt.plot(x + 1, color = "0.5") # 使用html最常用的16进制表示 plt.plot(x + 2, color = "#FF00FF") # 使用RGB元组的形式 plt.plot(x + 3, color = (0.1, 0.2, 0.3)) plt.show()
对于下面三种对颜色的设置,可以通过百度轻轻松松获取到,直接搜索颜色代码就可以,会提示很多,随便选一个自己认为合适的就可以。
2.点(marker)的样式(共有23种)
character | description |
---|---|
'8' | octagon |
'.' | point marker |
',' | pixel marker |
'o' | circle marker |
'v' | triangle_down marker |
'^' | triangle_up marker |
'<' | triangle_left marker |
'>' | triangle_right marker |
'1' | tri_down marker |
'2' | tri_up marker |
'3' | tri_left marker |
'4' | tri_right marker |
's' | square marker |
'p' | pentagon marker |
'*' | star marker |
'h' | hexagon1 marker |
'H' | hexagon2 marker |
'+' | plus marker |
'x' | x marker |
'D' | diamond marker |
'd' | thin_diamond marker |
'|' | vline marker |
'_' | hline marker |
#!/usr/bin/python #coding: utf-8 import numpy as np import matplotlib.pyplot as plt x = np.arange(1, 6) # 在画多条线段的时候,如果说对颜色没有特别的要求,其实没必要进行指定, # matplotlib会自动的设置颜色的类型,便于区分 # marker 显式指定的话,画出的是线段, # 如果不显式指定,画出的是给定的类型,显示结果是一些点,比如使用 _(下划线) 的话, # matplotlib内部也会分辨出是marker对象 plt.plot(x - 1, "o") plt.plot(x, marker = "o") plt.plot(x + 1, marker = "1") plt.plot(x + 2, marker = "_") plt.plot(x + 3, marker = ".") plt.show()
3.线的样式
线共有四种样式, 不需要显示指定
- 实线
-- 虚线
-. 点划线
: 点线
#!/usr/bin/python #coding: utf-8 import numpy as np import matplotlib.pyplot as plt x = np.arange(10) plt.plot(x, "--") plt.plot(x + 1, "-") plt.plot(x + 2, "-.") plt.plot(x + 3, ":") plt.show()
4.样式字符串
可以将颜色,点型,线型写成一个字符串(颜色只能是内建的8种颜色类型的一种,不能是后面提到的那三种情况,测试结果是这样的)
#!/usr/bin/python
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
plt.plot(x, "g8:")
plt.plot(x + 1, "b4--")
plt.plot(x + 2, "cH-.")
plt.plot(x + 3, "kH-")
plt.show()
相关文章推荐
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- Python一些使用技巧
- 使用Python中的Turtle库绘制简单的图形
- Python使用matplotlib实现绘制自定义图形功能示例
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- 绘制图形与3D增强技巧(五)----多边形图元的使用及其他
- 使用python matplotlib绘制简单图形
- Windows anaconda 2 安装python3 的一些使用技巧
- 使用python中turtle库绘制图形
- Python:使用pycha快速绘制办公常用图(饼图、垂直直方图、水平直方图、散点图等七种图形)
- 使用python爬虫抓站的一些技巧总结:进阶篇
- 【转】Python使用urllib2写爬虫抓站的一些技巧
- python中import的一些使用技巧
- 使用python爬虫抓站的一些技巧总结:进阶篇
- 使用python爬虫抓站的一些技巧总结:进阶篇
- 使用Python对IP进行转换的一些操作技巧小结
- 使用Python对IP进行转换的一些操作技巧小结
- Python实现在tkinter中使用matplotlib绘制图形的方法示例
- 使用python 爬虫抓站的一些技巧总结