[PYTHON] Draw a graph with matplotlib from a csv file

at first

Recently I worked on outputting a graph from a csv file with python. I'm new to pandas and matplotlib and it took me a while, so I'll summarize them briefly for future speedups.

code

input_csv_data.csv


No,Value
1,12
2,7
3,-19
4,28
5,60

import pandas as pd
import matplotlib.pyplot as plt

input_csv = pd.read_csv('./input_csv_data.csv')
first_column_data = input_csv[input_csv.keys()[0]]
second_column_data = input_csv[input_csv.keys()[1]]

plt.xlabel(input_csv.keys()[0])
plt.ylabel(input_csv.keys()[1])

plt.plot(first_column_data, second_column_data, linestyle='solid', marker='o')
plt.show()

image.png

Procedure summary

  1. Read the data with pandas
  2. Get column name / column data
  3. Set the axis name of the graph
  4. Make drawing settings

Reference article

--matplotlib official documentation https://matplotlib.org/3.3.3/api/_as_gen/matplotlib.pyplot.plot.html

Recommended Posts

Draw a graph with matplotlib from a csv file
Draw a loose graph with matplotlib
Draw a flat surface with a matplotlib 3d graph
Draw a graph with NetworkX
Draw a graph with networkx
[Python] How to draw a line graph with Matplotlib
Draw a graph with Julia + PyQtGraph (2)
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib
Draw a graph with PySimple GUI
Study math with Python: Draw a sympy (scipy) graph with matplotlib
Make a gif animation from a serial number file with matplotlib
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
How to draw a graph using Matplotlib
Simply draw a graph by specifying a file
Draw a graph with PyQtGraph Part 1-Drawing
Create a graph with borders removed with matplotlib
How to read a CSV file with Python 2/3
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Draw a graph with PyQtGraph Part 3-PlotWidget settings
[Python] Draw a directed graph with Dash Cytoscape
How to draw a bar graph that summarizes multiple series with matplotlib
Band graph with matplotlib
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with PyQtGraph Part 6-Displaying a legend
Read line by line from a file with Python
Draw multiple photos in a graph from multiple folders
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
Forcibly draw something like a flowchart with Python, matplotlib
Python script to create a JSON file from a CSV file
Draw a graph with PyQtGraph Part 2--Detailed plot settings
[Python] How to draw a scatter plot with Matplotlib
Graph Excel data with matplotlib (1)
Draw netCDF file with python
Graph Excel data with matplotlib (2)
Download csv file with python
[Python] Read the csv file and display the figure with matplotlib
Access the file with a relative path from the execution script.
[Visualization] I want to draw a beautiful graph with Plotly
A python graphing manual with Matplotlib.
[Python] Write to csv file with Python
Build a deb file with Docker
Draw Japanese with matplotlib on Ubuntu
Draw a beautiful circle with numpy
Draw retention rate graph in Matplotlib
Let's make a graph with python! !!
Easy to draw graphs with matplotlib
Make a nice graph with plotly
Draw Lyapunov Fractal with Python, matplotlib
Write a stacked histogram with matplotlib
Easily draw a map with matplotlib.basemap
Create a file uploader with Django
Read a file in Python with a relative path from the program
[Python] Read a csv file with a large data size using a generator
Get OCTA simulation conditions from a file and save with pandas
Create and return a CP932 CSV file for Excel with Chalice
Multiple selections with Jupyter
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI