Reputation: 51
I a trying to plot values from csv file. there are three columns which i can print them out, however, it doesnt plot the values. Any suggestions how to fix the code? Thanks in advance
import matplotlib.pyplot as plt
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import sys
from scipy import interpolate
from scipy.interpolate import griddata
import csv
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
with open('text.csv', 'r') as f:
obj = csv.reader(f)
X, Y, Z = [], [], []
for i,row in enumerate(obj):
if i>0:
xstring = row[0]
ystring = row[1]
zstring= row[2]
## print (xstring, ystring, zstring)
zdata = float(zstring)
xdata = float(ystring)
ydata = float(xstring)
ax.scatter3D(xdata, ydata, zdata);
plt.show()
Upvotes: 0
Views: 1832
Reputation: 2056
If I understand your intention correctly, you want to append the xdata,ydata,zdata
from each row in the file to the X, Y, Z
lists and in the end plot (scatter) these lists.
However, your code doesn't append to the lists inside the loop, so you end up applying scatter
just on the last xdata, ydata, zdata
.
Upvotes: 1