import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# 解决中文显示问题
plt.rcParams['font.sans-serif'] = ['STLiti'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
# 有中文出现的情况,需要u'内容'
fig = plt.figure()
ax1 = fig.add_subplot(111)
#设置标题
ax1.set_title('折线图')
#设置X轴标签
plt.xlabel('X')
#设置Y轴标签
plt.ylabel('Y')
x=np.linspace(-10,10,100)# -10到10平均分成100份
y=x**3
# plt.plot(x,y) # 方式一
ax1.plot(x, y, color='green', linestyle='dashed', marker='o',
markerfacecolor='blue', markersize=12)
#设置图标
plt.legend('x')
plt.show()
plt.plot()参数设置
| Property | Value Type |
| alpha |
控制透明度,0为完全透明,1为不透明 |
| 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 |
颜色设置 |
| 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 |
图示 |
| 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 |