【发布时间】:2016-08-04 00:36:05
【问题描述】:
我是pandas 和matplotlib 的新手。无法获得准确的参考来绘制我的DataFrame,其架构如下
schema = StructType([
StructField("x", IntegerType(), True),
StructField("y", IntegerType(), True),
StructField("z", IntegerType(), True)])
喜欢绘制 3d 图 w.r.t。 x、y 和 z
这是我使用的示例代码
import matplotlib.pyplot as pltt
dfSpark = sqlContext.createDataFrame(tupleRangeRDD, schema) // reading as spark df
df = dfSpark.toPandas()
fig = pltt.figure();
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(df['x'], df['y'], df['z'])
我得到一个空的图表。肯定错过了什么。有什么指点吗?
-谢谢
Request-1:打印 df
def print_full(x):
pd.set_option('display.max_rows', len(x))
print(x)
pd.reset_option('display.max_rows')
print_full(df)
前 10 名的结果
x y z
0 301 301 10
1 300 301 16
2 300 300 6
3 299 301 30
4 299 300 20
5 299 299 14
6 298 301 40
7 298 300 30
8 298 299 24
9 298 298 10
10 297 301 48
【问题讨论】:
-
df 是否包含任何内容?如果是这样,您可以在您的问题中打印 df.head(n=10) 吗?
-
通过打印 df 更新我的问题
标签: python numpy pandas matplotlib dataframe