Jun-01-2018, 07:37 PM
It is in the good direction but you are mixing 2 methods and reading the same file twice for no reason.
First you read the file with pandas, and later you read it again directly.
In pandas you cut at the desired row... but forgot to do something with the result. For the data read with numpy, you plot it right, but you are not throwing away the data after the minimum area.
Last, you mix the pyplot style plotting (typical when working from a command line) with the "OOP" style for matplotlib (better when writing scripts)
I just cleaned up the version using numpy, if you prefer to use pandas, just change the line of the loadtxt and the references to pressure, area... with df.pressure, df.area and so on.
First you read the file with pandas, and later you read it again directly.
In pandas you cut at the desired row... but forgot to do something with the result. For the data read with numpy, you plot it right, but you are not throwing away the data after the minimum area.
Last, you mix the pyplot style plotting (typical when working from a command line) with the "OOP" style for matplotlib (better when writing scripts)
I just cleaned up the version using numpy, if you prefer to use pandas, just change the line of the loadtxt and the references to pressure, area... with df.pressure, df.area and so on.
import matplotlib.pyplot as plt import numpy as np # Read the input data only once area, pressure, pixel = np.loadtxt ("data.csv", delimiter=",", skiprows=1, unpack=True) # Find the minimum index rowmin = area.argmin() # Ignore completely after the desired index... area = area[:rowmin+1] pressure = pressure[:rowmin+1] pixel = pixel[:rowmin+1] # Fine control of the matplotlib, you can use GridSpec to do fancy graphs... fig = plt.figure() ax1 = fig.add_subplot(1, 1, 1) # Plot in the first axis ax1.plot(area, pressure, label='area/pressure!', color='b') # And decorate it ax1.set_xlabel('area', color='b') ax1.set_ylabel('Pressure', color='b') ax1.tick_params('y', colors='b') # Now plot in the secondary axes ax2 = ax1.twinx() ax2.plot(area, pixel, color='r') ax2.set_ylabel('Intensity (measured by average pixel value)', color='r') ax2.tick_params('y', colors='r') # ax1.set_title('Kibron Trough Pressure-Area-Intensity Graph') ax1.legend() plt.show()