*Hi,

I am trying to plot a 3D surface plot. I have a list of x,y,z values. They are all of different dimensions.

y1   y2   y3   y4...

x1 z11 z12 z13 z14
x2 z21 z22 z23 ....
x3 .................
x4
x5

.
.
.
etc..*

import csv 
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import time
import pylab as p
import mpl_toolkits.mplot3d.axes3d as p3

fname = "C:\Users\Desktop\Temperature.csv"

depth_list = []
tempr_list = []

with open(fname) as fin:
    for ix, line in enumerate(fin):
        line = line.rstrip()
        line_list = line.split(';')
        if ix == 0:
            time_list = line_list[1:]
        else:
            depth_list.append(float(line_list[0]))
            tempr_list.append([float(t) for t in line_list[1:]])

plt.plot(depth_list, tempr_list)

fig = plt.figure()
ax = fig.gca(projection='3d')

#ax.plot_trisurf(time_list, depth_list, tempr_list, cmap=cm.jet, linewidth=0.2)

plt.show()
timelist = []
for i in range(len(time_list)):
    timelist = time.mktime(time.strptime(time_list[i], "%d.%m.%Y %H:%M:%S"))
ax.plot3D(depth_list, tempr_list, timelist)

The error I get, I'll just paste the entire thing:

ValueError: setting an array element with a sequence.

I tried converting the timelist to string, but its not working.. Not quite sure what to do:(

You'll have better luck posting on the matplotlib forums.

Something tells me that time_list[i] is not actually a single value, but is likely an interable (tuple or list).

I'd also recommend using pandas, importing the data into your dataframe, and using a TimeIndex as the label axis. If you're working with timeseries data, it will really give you a lot more power than just basic python.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.