I am currently using matplotlib to graph a set of data from a CSV file. The data is not displaying correctly. This is what I am expecting plus this is what Excel gives me (the orange part, ignore the formatting).
Excel Graph
The following is what my code generated.
Matplotlib Graph
The following is the code that I used to generate this graph.
import matplotlib.pyplot as pl
import pandas as pd
import numpy as np
#Get data
data = pd.read_csv("P:/#############/Noise_Test_Oscilliscope_Data/scope_1.csv")
time = data['x-axis'].to_list()
volt_1 = data['1'].to_list()
volt_2 = data['2'].to_list()
#Removes strings at beginning of data
time.pop(0)
volt_1.pop(0)
volt_2.pop(0)
#Gets maximum voltage
maxv = float(max(volt_1))
maxv_pos = float(time[volt_1.index(max(volt_1))])
#Plots data
pl.xlabel("Time")
pl.ylabel("Volts")
pl.plot(time,volt_1, 'b-')
pl.plot(maxv_pos, maxv, 'go')
pl.show()
I know something is wrong, because the maximum point of the graph is supposed to be somewhere in the middle of the data. However, when I look for and plot the maximum point (green dot), it shows it at the very beginning of the graph. I also know that the excel graph is the correct one, because I pulled the data off of an oscilloscope and have a picture of what the waveform is supposed to look like. What am I doing wrong in my python code?
dhout23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.