Python Forum
2D to 3D plots - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: 2D to 3D plots (/thread-14093.html)



2D to 3D plots - ekq378 - Nov-14-2018

I'm looking to transverse this 2D plot into a 3D plot. The third axis would be the different sensors so they're not overlapping each other. I'm rather new to python so just looking for ideas for the simplest solution to help me out. Below is the code I used. In my code I wanted to basically just load sensors = data_file[:, 13], data_file[:, 15], data_file[:, 17], data_file[:, 19], data_file [:,21], data_file [:, 23] but this didn't work for me when I went to plot the 2D plot so I had to include all columns from 12-24.
# Numpy (data import, manipulation, export)
# Matplotlib (create trends)
import matplotlib.pyplot as plt
import numpy as np

#load data file
data_file = np.genfromtxt('500Hz_0.txt', delimiter='\t')

# create time vector from imported data (starts from index 0)
time = data_file[:, 0]
# parse good sensor data from imported data
time = time - time[0]
sensors = data_file[:,12:24]

sensors = sensors * -1

# export data
# stack time and avg as column vectors
my_data = np.vstack((time,sensors.T))
# transpose data
my_data = my_data.T
# save text file with tab delimiter
np.savetxt('newfile.txt',my_data,delimiter='\t')

plt.plot(time,sensors[:,1],'r')
plt.plot(time,sensors[:,3],'b')
plt.plot(time,sensors[:,5],'g')
plt.plot(time,sensors[:,7],'y')
plt.plot(time,sensors[:,9],'k')
plt.plot(time,sensors[:,11],'c')

# add text labels to the plot
plt.legend(['Sensor 1','Sensor 2', 'Sensor 3', 'Sensor 4', 'Sensor 5', 'Sensor 6'])
plt.xlabel('Time (sec)')
plt.ylabel('Voltage')

# show the figure on the screen (pauses execution until closed)
plt.show()