我对熊猫和matplotlib还不熟悉。无法获取对
绘制模式如下的“DataFrame”
schema = StructType([
StructField("x", IntegerType(), True),
StructField("y", IntegerType(), True),
StructField("z", IntegerType(), True)])
喜欢画三维图形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'])
I am getting a empty graph plot. definitely missing something. Any pointers?
-Thx
Request-1: Print df
def print_full(x):
pd.set_option('display.max_rows', len(x))
print(x)
pd.reset_option('display.max_rows')
print_full(df)
Result of top 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
.plot_surface()
将‘2Darrays`作为输入,而不是'1D
DataFrame列。 这已经解释得很清楚了 [这里](https://stackoverflow.com/questions/9170838/surface-plots-in- matplotlib),以及下面的代码,说明如何可以到达 使用“DataFrame”输入的所需格式。下面用小调转载 修改,如附加注释。 然而,另一种选择是 [
.plot\u trisurf()`](http://matplotlib.org/mplŠu toolkits/mplot3d/tutorial.htmlŠtri-
曲面图)使用“1D”输入。我在书中加了一个例子
密码。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from mpl_toolkits.mplot3d import Axes3D
## Matplotlib Sample Code using 2D arrays via meshgrid
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = np.sin(R)
fig = plt.figure()
ax = Axes3D(fig)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.title('Original Code')
plt.show()
## DataFrame from 2D-arrays
x = X.reshape(1600)
y = Y.reshape(1600)
z = Z.reshape(1600)
df = pd.DataFrame({'x': x, 'y': y, 'z': z}, index=range(len(x)))
# Plot using `.trisurf()`:
ax.plot_trisurf(df.x, df.y, df.z, cmap=cm.jet, linewidth=0.2)
plt.show()
# 2D-arrays from DataFrame
x1 = np.linspace(df['x'].min(), df['x'].max(), len(df['x'].unique()))
y1 = np.linspace(df['y'].min(), df['y'].max(), len(df['y'].unique()))
"""
x, y via meshgrid for vectorized evaluation of
2 scalar/vector fields over 2-D grids, given
one-dimensional coordinate arrays x1, x2,..., xn.
"""
x2, y2 = np.meshgrid(x1, y1)
# Interpolate unstructured D-dimensional data.
z2 = griddata((df['x'], df['y']), df['z'], (x2, y2), method='cubic')
# Ready to plot
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(x2, y2, z2, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.title('Meshgrid Created from 3 1D Arrays')
plt.show()
通常,人们会在打印输出(数据帧)时询问堆栈溢出问题。如果有一种方法可以将数据帧数据快速加载到对象中,那么这是很方便的。 从数据帧字符串(可能格式正确,也可能格式不正确)加载数据帧的最有建议的方法是什么? 如果要将以下字符串作为数据帧加载,您会怎么做? 此类型与您在文件中找到的更相似。 注意:以下两个链接不涉及示例-1中提出的具体情况。我认为我的问题不是重复的原因是,我认为不能使用已经发布在这些链接
问题内容: 我有一个HTML报告,由于列很多,因此需要横向打印。是否有一种方法可以执行此操作,而无需用户更改文档设置? 在浏览器中有哪些选项。 问题答案: 在CSS中,您可以设置@page属性,如下所示。 @page是CSS 2.1规范的一部分,但是问题的答案并未突出显示[@Page{size:landscape}是否已过时?: CSS 2.1不再指定size属性。CSS3 Paged Media
本文向大家介绍Java如何调用TSC打印机进行打印详解,包括了Java如何调用TSC打印机进行打印详解的使用技巧和注意事项,需要的朋友参考一下 前言 最近项目中用到了打印机,最开始的完全不懂,现在弄好了,所以做了总结,该篇包括后台的调用打印(两种方式)跟前端的js的打印,但是只有IE现在支持打印,而且如果想远程连接打印机,二维码的生成和直接由打印机的命令进行操作,就要把修改浏览器的安全配置,下面再
我使用Spyder和Python3.6,数据框最多有3000行,当它被发送到打印时,我会截短数据,即使我使用打印(selecc.to_string()),当数据框打印到TXT文件时,我可以看到完整的数据,使用代码:np。savetxt('ATPRes.txt',selecc,fmt=“%s”)我们将非常感谢您的帮助,提前感谢!P.S.已经尝试了先前答案中给出的选项--
问题内容: 使用Java,我需要在未本地安装的网络打印机上进行打印。我只知道打印机名称。我看过的所有教程都以类似以下内容开始: 问题是可能没有安装打印机,因此在这种情况下服务将为空。我需要直接设置打印机名称,而不仅仅是通过可见的打印机枚举。 问题答案: 如果Java AWT Printing未向运行打印应用程序的Windows / Active Directory用户注册,则无法通过路径找到打印机
相关:如何在(unix)shell脚本中漂亮地打印JSON? 是否有(unix)shell脚本以人类可读的形式格式化XML? 基本上,我想让它转换以下内容: ...变成这样的东西: