Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2D to 3D plots
#1
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()
Reply


Messages In This Thread
2D to 3D plots - by ekq378 - Nov-14-2018, 06:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plots issue shane1236 1 2,048 Aug-06-2019, 10:00 AM
Last Post: shane1236
  Add space between plots AdWill97 0 2,033 May-15-2019, 02:04 PM
Last Post: AdWill97
  Three-dimensional Contour Plots minifizikus 1 3,243 Sep-13-2018, 10:56 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020