open()打开文件。如果出现unicodedecodeerror,加上encoding='utf-8'选项。用spyder调试时,待打开文件存放目录应该放在源文件目录下?
Plotly 绘图底层使用的是plotly.js,它是基于D3.sj、stack.gl和SVG,用JavaScript在网页上实现类似MATLAB和Python Matplotiib的图形展示功能。
支持2D、3D图形,交互流畅,可以满足一般科学计算的需要。目前,已经有python 、MATLAB 、R 语言、Jupyter等多种版本的API接口。
# -*- coding: utf-8 -*-
Spyder Editor
This is a temporary script file.
import re
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # 空间三维画图
#import plotly
import plotly.graph_objs as go
import plotly.offline
stepCounts = 790
#定义position数组
positionX = [0.0]*stepCounts
positionY = [0.0]*stepCounts
positionZ = [0.0]*stepCounts
f = open("OutPut.txt",'r',encoding='utf-8')
'''s = f.read()'''
s = f.readline() #跳过第一行'''
for jj in range(0,stepCounts,1):
s = f.readline()
s1 = re.split(' +',s)
positionX[jj] = float(s1[12])
positionY[jj] = float(s1[13])
positionZ[jj] = float(s1[14])
'''# 绘制散点图
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(positionX, positionY, positionZ, c='r', label='顺序点')
# 绘制图例
ax.legend(loc='best')
# 添加坐标轴(顺序是Z, Y, X)
ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})
ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})
ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'})
plt.show()
data = [go.Scatter3d(x=positionX,y=positionY,z=positionZ,mode='markers',
opacity=0.9,)]
layout = go.Layout(title='三维散点',
autosize=False,
width=900,
height=900,
margin=dict(
l=65,
r=50,
b=65,
yaxis=dict(title='y',#设置坐标轴的标签
titlefont=dict(color='rgb(148, 103, 189)',size=24),#设置坐标轴标签的字体及颜色
tickfont=dict(color='rgb(148, 103, 189)',size = 24,),#设置刻度的字体大小及颜色
showticklabels=False,#设置是否显示刻度
#设置刻度的范围及刻度
autorange=False,range=[-1.0, 1.0],type='linear',
fig = go.Figure(data=data,layout = layout)
#fig.update_layout()
#fig.show()
plotly.offline.plot(fig)