From file to graph drawing in Python. Elementary elementary

It doesn't matter if it's sin or cos, so I just want to plot the external data for the time being!

Memo

Drawing target

A random list of 100 values.

A


$ perl -le 'print rand (10) for 0 .. 99' > rand.txt

matplotlib only

After executing A, execute ↓ in the same directory

python


import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
f = open("rand.txt", "r")
x = []
y = []
for i, line in enumerate(f):
    x.append(i)
    y.append(float(line))
plt.title("data")
plt.xlabel("x")
plt.ylabel("y")
plt.plot(x,y)
plt.savefig("graph.png ")

If you use pandas

Similarly.

python


import matplotlib
matplotlib.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("rand.txt", header=None)
data.columns= [ 'test' ]
data.plot()
plt.savefig("graph.png ")

graph.png

Recommended Posts

From file to graph drawing in Python. Elementary elementary
Graph drawing in python
Convert psd file to png in Python
Convert from Markdown to HTML in Python
File operations in Python
File processing in Python
Changes from Python 3.0 to Python 3.5
Import Excel file from Python (register to DB)
How to create a JSON file in Python
File operations in Python
From re-environment construction of Python to graph drawing (on visual studio code)
Draw graph in python
Sample to put Python Kivy in one file
I tried to graph the packages installed in Python
Parse a JSON string written to a file in Python
App development to tweet in Python from Visual Studio 2017
Until drawing a 3D graph in Python on windows10
A memorandum to run a python script in a bat file
I want to randomly sample a file in Python
[Python] Change standard input from keyboard to text file
How to download files from Selenium in Python in Chrome
Procedure to exe python file from Ubunts environment construction
[Work efficiency] How to change file names in Python
Python script to create a JSON file from a CSV file
Post from Python to Slack
Drawing candle charts in python
To flush stdout in Python
Cheating from PHP to Python
Download the file in Python
Login to website in Python
OCR from PDF in Python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Switch from python2.7 to python3.6 (centos7)
Speech to speech in python [text to speech]
Connect to sqlite from python
How to develop in Python
Post to Slack in Python
Assigned scaffolding macro in Python script file to F12 key
How to slice a block multiple array from a multiple array in Python
Change the standard output destination to a file in Python
How to import a file anywhere you like in Python
How to sample from any probability density function in Python
Allow Python to select strings in input files from folders
Hit REST in Python to get data from New Relic
Get macro constants from C (++) header file (.h) in Python
[Python] How to change EXCEL file saved in xlsb to xlsx
(Translation) Native connection from Python to Hadoop file system (HDFS)
Convert Excel file to text in Python for diff purposes
Call Matlab from Python to optimize
Execute Python script from batch file
[Python] How to do PCA in Python
File / folder path manipulation in Python
Convert markdown to PDF in Python
[Python] Write to csv file with Python
Save the binary file in Python
Linebot creation & file sharing in Python
Create folders from '01' to '12' with python
Post from python to facebook timeline
How to use SQLite in Python
Output to csv file with Python
[Lambda] [Python] Post to Twitter from Lambda!