Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib

Suppose you want to plot such a csv file with python (matplotlib). ..

$ head tmp2
1000,0.059820690
2000,0.093225007
3000,0.139737644
4000,0.185947643
5000,0.249426903
6000,0.280377022
7000,0.325663341
8000,0.374918515
9000,0.421537361
10000,0.467402504

■ In the case of scatter (scatter plot), plot one by one with a for statement. ■ In the case of plot (line), pass it at once in the list.

It is an image.

Take a look at the code. .. ..

In the case of a polygonal line (note lines 14-16)

     1import numpy as np
     2import matplotlib.pyplot as plt
     3
     4data_set = np.loadtxt(
     5    fname="tmp2",
     6    dtype="float",
     7    delimiter=",",
     8)
     9
    10x = []
    11y = []
    12
    13for data in data_set:
    14    #plt.scatter(data[0], data[1], c='black')                                                                                                                                         
    15    x.append(data[0])
    16    y.append(data[1])
    17
    18plt.plot(x, y)
    19
    24plt.show()

plot.png

For scatter plots (note lines 14-16)

     1import numpy as np
     2import matplotlib.pyplot as plt
     3
     4data_set = np.loadtxt(
     5    fname="tmp2",
     6    dtype="float",
     7    delimiter=",",
     8)
     9
    10x = []
    11y = []
    12
    13for data in data_set:
    14    plt.scatter(data[0], data[1], c='black')                                                                                                                                         
    15    #x.append(data[0])
    16    #y.append(data[1])
    17
    18plt.plot(x, y)
    19
    24plt.show()

https://github.com/RuoAndo/qiita/blob/master/plot-x-y.py

scatter.png

Recommended Posts

Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib
[Python] How to draw a scatter plot with Matplotlib
Draw a graph with matplotlib from a csv file
[Python] How to draw a line graph with Matplotlib
[Python] Read the csv file and display the figure with matplotlib
How to draw a vertical line on a heatmap drawn with Python seaborn
Read the file with python and delete the line breaks [Notes on reading the file]
How to read a CSV file with Python 2/3
Create 3D scatter plot with SciPy + matplotlib (Python)
Read line by line from a file with Python
Visualize grib2 on a map with python (matplotlib)
Various ways to read the last line of a csv file in Python
I tried to touch the CSV file with Python
Make a breakpoint on the c layer with python
Forcibly draw something like a flowchart with Python, matplotlib
Draw netCDF file with python
Download csv file with python
Study math with Python: Draw a sympy (scipy) graph with matplotlib
Create a new csv with pandas based on the local csv
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
Notes on coloring by value in the matplotlib scatter plot
Create plot animation with Python + Matplotlib
Extract the xz file with python
A python graphing manual with Matplotlib.
[Python] Write to csv file with Python
Draw Japanese with matplotlib on Ubuntu
Output to csv file with Python
Continuously color with matplotlib scatter plot
Draw Lyapunov Fractal with Python, matplotlib
Lognormal probability plot with Python, matplotlib
Control the motor with a motor driver using python on Raspberry Pi 3!
After calling the Shell file on Python, convert CSV to Parquet.
Read a file in Python with a relative path from the program
The idea of feeding the config file with a python file instead of yaml
[Python] Read a csv file with a large data size using a generator
Creating a simple PowerPoint file with Python
[Python] Set the graph range with matplotlib
The story of making a university 100 yen breakfast LINE bot with Python
Read and format a csv file mixed with comma tabs with Python pandas
A memo organized by renaming the file names in the folder with python
Read CSV file with python (Download & parse CSV file)
Check the existence of the file with python
Extract lines that match the conditions from a text file with python
Add 95% confidence intervals on both sides to the diagram with Python / Matplotlib
A memo with Python2.7 and Python3 on CentOS
Map rent information on a map with python
Search the maze with the python A * algorithm
Let's read the RINEX file with Python ①
[Python] If you want to draw a scatter plot of multiple clusters
How to put a line number at the beginning of a CSV file
Read the file line by line in Python
Download files on the web with Python
Read the file line by line in Python
Plot CSV of time series data with unixtime value in Python (matplotlib)
[Python, ObsPy] I drew a beach ball on the map with Cartopy + ObsPy.
[Python] A progress bar on the terminal
Python / numpy> Read the data file with the item name line> Use genfromtxt ()
[Python] Read the specified line in the file
[Implementation example] Read the file line by line with Cython (Python) from the last line
I made a configuration file with Python
A Python script that reads a SQL file, executes BigQuery and saves the csv