iMo*_*o51 2 python plot matplotlib dataframe pandas
使用熊猫数据框的内置功能进行绘制,例如,如下所示的未堆积面积图:
df = pd.DataFrame(np.random.randn(11, 3)+3, columns=['r', 'g', 'b'])
df.plot(kind='area', stacked=False, alpha=0.75)
Run Code Online (Sandbox Code Playgroud)
产生这样的东西:

一个事后如何改变仅一条线的样式,例如改变其颜色,线宽和不透明度等?
如@StefanJansen所述,您可以color通过访问lines给定的中的来编辑行Axes。
您还可以像这样修改其他属性:
ax.lines[0].set_linewidth(2) # set linewidth to 2
ax.lines[0].set_linestyle('dashed') # other options: 'solid', 'dashdot` or `dotted`
ax.lines[0].set_alpha(0.5) # Change the transparency
ax.lines[0].set_marker('o') # Add a circle marker at each data point
ax.lines[0].set_markersize(2) # change the marker size. an alias is set_ms()
ax.lines[0].set_markerfacecolor # or set_mfc()
ax.lines[0].set_markeredgecolor # or set_mec()
Run Code Online (Sandbox Code Playgroud)
要更改曲线下的面积,您要访问中collections存储的内容Axes。有用的属性是color和alpha:
ax.collections[0].set_color('yellow')
ax.collections[0].set_alpha(0.3)
Run Code Online (Sandbox Code Playgroud)
显然,您可以0在这些示例中更改索引以修改另一个lines/ collections。
| 归档时间: |
|
| 查看次数: |
764 次 |
| 最近记录: |