Python Graph X-Axis from CSV File with Python

  • Thread starter Thread starter chipotleaway
  • Start date Start date
  • Tags Tags
    Python
Click For Summary
To create a graph using a .csv file with three columns—independent variable, dependent variable, and uncertainty in the dependent variable—the correct approach involves explicitly passing the individual columns to the plotting function. Initially, using a single 2D array with the command "pylab.plot(data, 'ko')" can lead to confusion, as it may plot all columns against the row index instead of the intended x and y axes. The recommended solution is to use "pylab.plot(data[0], data[1], 'ko')" to ensure that the independent variable is plotted on the x-axis and the dependent variable on the y-axis, resulting in an accurate graph representation.
chipotleaway
Messages
174
Reaction score
0
How do if you have a .csv file with 3 columns (independent, dependent, uncertainty in dependent variable), how do you make a graph so that the independent variable is the x-axis and the dependent is the y axis?

All I've done is
Code:
pylab.plot(data,"ko")
pylab.show()

The graph I get seems to have plotted the independent variable as the dependent...as well as the other two columns
 
Technology news on Phys.org
hhhmmm...passing a single 2D array may be causing plot to plot all columns against the row index...try passing the individual columns explicitly, something like plot(data[0],data[1],'ko')
 
  • Like
Likes 1 person
Thanks, got it now. Looks like it's plotting everything correctly
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
22K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
9K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K