from matplotlib import pyplot as plt
x = range(1,10) #x轴的位置
y = [6,7,12,12,15,17,15,20,18] #y轴的位置
#传入x,y,通过plot画图,并设置折线颜色、透明度、折线样式和折线宽度 标记点、标记点大小、标记点边颜色、标记点边宽
plt.plot(x,y,color='red',alpha=0.3,linestyle='--',linewidth=5,marker='o'
,markeredgecolor='r',markersize='20',markeredgewidth=10)
plt.show()
效果截图:
标记类型:
|
marker
|
symbol
|
description
|
"."
|
|
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
|
"P"
|
|
plus (filled)
|
"*"
|
|
star
|
"h"
|
|
hexagon1
|
"H"
|
|
hexagon2
|
"+"
|
|
plus
|
"x"
|
|
x
|
"X"
|
|
x (filled)
|
"D"
|
|
diamond
|
"d"
|
|
thin_diamond
|
"|"
|
|
vline
|
"_"
|
|
hline
|
0
(
TICKLEFT
)
|
|
tickleft
|
1
(
TICKRIGHT
)
|
|
tickright
|
2
(
TICKUP
)
|
|
tickup
|
3
(
TICKDOWN
)
|
|
tickdown
|
4
(
CARETLEFT
)
|
|
caretleft
|
5
(
CARETRIGHT
)
|
|
caretright
|
6
(
CARETUP
)
|
|
caretup
|
7
(
CARETDOWN
)
|
|
caretdown
|
8
(
CARETLEFTBASE
)
|
|
caretleft (centered at base)
|
9
(
CARETRIGHTBASE
)
|
|
caretright (centered at base)
|
10
(
CARETUPBASE
)
|
|
caretup (centered at base)
|
11
(
CARETDOWNBASE
)
|
|
caretdown (centered at base)
|
"None"
,
" "
or
""
|
|
nothing
|
'$...$'
|
|
Render the string using mathtext. E.g
"$f$"
for marker showing the letter
f
.
|
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, such that the created path is encapsulated inside the unit cell.
|
|
path
|
|
A
Path
instance.
|
(numsides, 0, angle)
|
|
A regular polygon with
numsides
sides, rotated by
angle
.
|
(numsides, 1, angle)
|
|
A star-like symbol with
numsides
sides, rotated by
angle
.
|
(numsides, 2, angle)
|
|
An asterisk with
numsides
sides, rotated by
angle
.
|
代码示例:from matplotlib import pyplot as pltx = range(1,10) #x轴的位置y = [6,7,12,12,15,17,15,20,18] #y轴的位置#传入x,y,通过plot画图,并设置折线颜色、透明度、折线样式和折线宽度 标记点、标记点大小、标记点边颜色、标记点边宽plt.plot(x,y,color='red',alpha=0.3,linestyle='--',linewidth=5,marker='o' ,marke
Matplotlib
是 Python 的绘图库。 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案。 它也可以和图形工具包一起使用,如 PyQt 和 wxPython。
今天是数据处理专题的第11篇文章,我们继续来介绍
matplotlib
这个包的使用方法。
在上一篇文章当中我们介绍了
matplotlib
当中subplot的概念以及用法,今天我们将会来介绍
matplotlib
绘图中的一些具体的设置,可以让我们画出来的图像更加丰富,表现力也更强。
我们之前绘制的图像都是蓝色的,这也是
matplotlib
的默认
颜色
。我们可以使用color这个参数来设置图像的
颜色
,比
在用python画散
点
图的时候想
标记
出
特定
的
点
,比如在某些
点
的外围加个空心圆,一样可以通过plt.scatter实现
import
matplotlib
.pyplot as plt
x = [[1, 3], [2, 5]]
y = [[4, 7], [6, 3]]
for i in range(len(x)):
plt.plot(x[i], y[i], color='r')
plt.scatter(x[i], y[i], color='b')
plt.scatter(x[i], y[i], color='', marker='o', edgecolors='g', s=200)
def demo_test():
a=np.array([0.15,0.16,0.14,0.17,0.12,0.16,0.1,0.08,0.05,0.07,0.06]);
max_indx=np.argmax(a)#max value index
min_...
import numpy as np
plt.style.use(‘classic’)
plt.rcParams[‘font.sans-serif’] = [‘SimHei’] #解决中文显示
plt.rcParams[‘axes.unicod...
Matplotlib
折线图
(绘图实例+代码详解)
折线图
(line chart)是我们日常工作、学习中经常使用的一种图表,它可以直观的反映数据的变化趋势。与绘制柱状图、饼状图等图形不同,
Matplotlib
并没有直接提供绘制
折线图
的函数,因此本节着重讲解如何绘制一幅
折线图
。
绘制单条折线
下面示例是关于用户活跃度的
折线图
:
import
matplotlib
.pyplot as plt
#准备绘制数据
x = ["Mon", "Tues", "Wed", "Thur", "Fri","Sat","Sun"
plot([x], y, [fmt], data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
点
和线的坐标由参数x,y提供。可选参数fmt是一个快捷字符串,用于定义
颜色
、
标记
符合和线条形状,例如:
>>>...
折线图
:
折线图
(line chart)是我们在数据分析、数据展示中经常使用的一种图表,它可以直观的反映数据的变化趋势。与绘制柱状图、饼状图等图形不同,
Matplotlib
并没有直接提供绘制
折线图
的函数。线图适用于分析数据随时间变化的趋势。例如,分析商品销量随时间的变化,预测未来的销售情况。
通过
matplotlib
.pyplot.plot函数来绘制
折线图
,plot函数已经.