如何在Python Pandas中设置Dataframe图的标记样式?

Rak*_*van 5 python pandas

我使用df.plot()来获取这个情节:

在此输入图像描述

我想将标记样式更改为圆形,以使我的绘图看起来像这样:

在此输入图像描述

另外,有没有办法在每个标记点上方显示y轴值?

cge*_*cge 9

标记非常简单.只是用df.plot(marker='o').

将y轴值添加到点之上会有点困难,因为您需要直接使用matplotlib,并手动添加点.以下是如何执行此操作的示例:

import numpy as np
import pandas as pd
from matplotlib import pylab

z=pd.DataFrame( np.array([[1,2,3],[1,3,2]]).T )

z.plot(marker='o') # Plot the data, with a marker set.
pylab.xlim(0,3) # Change the axes limits so that we can see the annotations.
pylab.ylim(0,4)
ax = pylab.gca()
for i in z.index: # iterate through each index in the dataframe
    for v in z.ix[i].values: # and through each value being plotted at that index
        # annotate, at a slight offset from the point.
        ax.annotate(str(v),xy=(i,v), xytext=(5,5), textcoords='offset points')
Run Code Online (Sandbox Code Playgroud)