pandas 熊猫简单的XY图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17506750/
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
Pandas simple X Y plot
提问by LonelySoul
Looks simple but I am not able to draw a X-Y chart with "dots" in pandas DataFrame. I want to show the subidas "Mark" on X Y Chart with X as ageand Y as fdg.
看起来很简单,但我无法在 Pandas DataFrame 中绘制带有“点”的 XY 图表。我想在 XY 图表上将subid显示为“Mark”,其中 X 为年龄,Y 为fdg。
Code so far
到目前为止的代码
mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22, 'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}]
df = pandas.DataFrame(mydata)
DataFrame.plot(df,x="age",y="fdg")
show()
回答by TomAugspurger
df.plot()
will accept matplotlib kwargs
. See the docs
df.plot()
将接受 matplotlib kwargs
。查看文档
mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22,
'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}]
df = pandas.DataFrame(mydata)
df = df.sort(['age']) # dict doesn't preserve order
df.plot(x='age', y='fdg', marker='.')
Reading your question again, I'm thinking you might actually be asking for a scatterplot.
再次阅读您的问题,我认为您实际上可能是在要求散点图。
import matplotlib.pyplot as plt
plt.scatter(df['age'], df['fdg'])
Have a look at the matplotlibdocs.
看看matplotlib文档。
回答by Nilani Algiriyage
Try following for a scatter diagram.
尝试以下散点图。
import pandas
from matplotlib import pyplot as plt
mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22,
'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}]
df = pandas.DataFrame(mydata)
x,y = [],[]
x.append (df.age)
y.append (df.fdg)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(y,x,'o-')
plt.show()