如何在 Python Pandas 中设置 Dataframe 图的标记样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35300159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:40:07 来源:igfitidea点击:
How to set marker style of Dataframe plot in Python Pandas?
提问by Rakesh Adhikesavan
回答by cge
The marker is pretty easy. Just use df.plot(marker='o')
.
标记很简单。只需使用df.plot(marker='o')
.
Adding the y axis value above the points is a bit more difficult, as you'll need to use matplotlib directly, and add the points manually. The following is an example of how to do this:
在点上方添加 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')