Line Color You can use the keyword argumentcoloror the shortercto set the color of the line: Example Set the line color to red: importmatplotlib.pyplotasplt importnumpyasnp ypoints = np.array([3,8,1,10]) plt.plot(ypoints, color ='r') ...
相同我们能够通过调用Line2D对象的get_*方法。或者plt.getp函数获取对象的属性值: >>>line.get_linewidth()1.0>>>plt.getp(lines[0],"color")# 返回color属性'r'>>>plt.getp(lines[1])# 输出所有属性alpha = 1.0animated = Falseantialiased or aa = Trueaxes = Axes(0.125,0.1;0.775x0.8)... 注意...
ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black') yticklabels.append(name) ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5), yticks=np.arange(len(linestyles)), yticklabels=yticklabels)#For each line style, add a text annotation with a small offset from#the r...
np.sin(x), label="zorder=2", zorder=2) # bottomplt.plot(x, np.sin(x + 0.5), label="zorder=3", zorder=3)plt.axhline(0, label="zorder=2.5", color="lightgrey", zorder=2.5)plt.title("Custom order of elements")l = plt.legend(loc="upper right")l.set_zorder(2.5) #...
'-.'dash-dot line style ':'dotted line style 折线图还可以又标记来凸显实际的数据点,matplotlib 创建一个连续的折线图,插入点之间有时分辨不出。标记可以是样式字符串的一部分,样式字符串中的线类型,标记类型必须在颜色后面。 plot(np.random.randn(30).cumsum(),color='r',linestyle='dashed',marker='s...
set_ylabel('Y2 data', color='b')#第二个y坐标轴 plt.show() 7、动画 代码语言:javascript 代码运行次数:0 运行 AI代码解释 from matplotlib import animation#引入新模块 fig,ax=plt.subplots() x=np.arange(0,2*np.pi,0.01)#数据为0~2PI范围内的正弦曲线 line,=ax.plot(x,np.sin(x))# line...
calendarplot(new_df['pm2_5'], fillcolor = 'grey', linecolor = 'w', linewidth = 0.1, cmap = 'jet', yearlabel_kws={'color':'black', 'fontsize':12}, fig_kws = dict(figsize=(10, 6), dpi=80)) #设置x轴刻度字体样式 plt.setp(ax[0].get_xticklabels(), fontproperties = '...
>>> line.get_alpha() == None True >>> line.get_color() 'blue' 3.设置属性的值 设置object 的某个属性对象的值,用 object.set_name(value) 一次性设置 object 多个属性对象的值,用 object.set(name1 = value1, name2 = value2) plt.setp(object, name1 = value1, name2 = value2) ...
line.get_linewidth() 1.0 plt.getp(lines[0], "color") # 返回color属性 'r' plt.getp(lines[1]) # 输出全部属性 alpha = 1.0 animated = False antialiased or aa = True axes = Axes(0.125,0.1;0.775x0.8) ... ... 注意getp函数只能对一个对象进行操作,它有两种用法: ...
'get_xminorticklabels', 'get_xscale', 'get_xticklabels', 'get_zorder'] 假设我们想自定义一个图形的坐标: x = np.linspace(0, 2, 100) fig, ax = plt.subplots # Create a figure and an axes. l1 = ax.plot(x, x, label="linear") ...