Simply draw a graph by specifying a file

Continuation of here.

sin or cos, whatever, I just want to plot the external data for the time being!

By the way.

Embedding is a toro. Let's specify it with an argument!

A memo. With various graph tools.

To use it, use rand.txt again, which I used there.

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

Python

GRAPH.py


import sys
import matplotlib
matplotlib.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv(sys.argv[1], header=None)
data.plot()
plt.savefig(sys.argv[2])

python


$ python GRAPH.py rand.txt graph.png

Just use sys.argv with ʻimport sys`.

R

https://www.r-project.org/

GRAPH.r


png(commandArgs(trailingOnly=TRUE)[2])
data = read.table(commandArgs(trailingOnly=TRUE)[1])
plot(data$V1, type="l")

python


$ Rscript ./GRAPH.r rand.txt graph2.png

It seems that the line number is implicitly treated as x only when y is V1 (first column).

gnuplot

http://www.gnuplot.info/

** 2019/01/19 update **

This is more intuitive. Since it is used as a one-liner, I will leave a note of -e [^ 1].

[^ 1]: Ideally, you can use -e and -c together, but ...

GRAPH.plt


#!/usr/bin/env gnuplot
set term png
set output ARG2
plot ARG1  u ($0):($1) notitle w l

python


$ gnuplot -c GRAPH.plt rand.txt graph3.png 

$ 0 indicates the "index".

Old memo

GRAPH.plt


#!/usr/bin/env gnuplot
set term png
set output o
plot f  u ($0):($1) notitle w l

python


$ gnuplot -e 'f="rand.txt";o="graph3.png "'  GRAPH.plt

psxy (GMT)

http://gmt.soest.hawaii.edu/projects/gmt

For psxy, I can't think of a way to omit x ...

python


$ perl -lne 'print join " ", $., $_' rand.txt | gmt psxy -R0/100/0/10 -Jx0.1/1 > graph4.eps
$ gmt psconvert -P graph4.eps

--With -R, draw x from 0 to 100 and y from 0 to 10. --With -Jx, x is multiplied by 0.1 and y is multiplied by 1.

Draw a graph with.

spark

https://github.com/holman/spark

By the way, spark

python


$ cat rand.txt| spark

spark.png

Recommended Posts

Simply draw a graph by specifying a file
Draw a graph by processing with Pandas groupby
Draw a graph with matplotlib from a csv file
Draw a graph with NetworkX
Draw a graph with networkx
Draw a graph with Julia + PyQtGraph (2)
Draw a loose graph with matplotlib
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a graph with PySimple GUI
Read the file by specifying the character code.
Draw a graph with PyQtGraph Part 1-Drawing
Draw a flat surface with a matplotlib 3d graph
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
How to draw a 3D graph before optimization
Draw a "breast curved surface" in a 3D graph (1)
Draw a graph with PyQtGraph Part 3-PlotWidget settings
[Python] Draw a directed graph with Dash Cytoscape
Simply display a line graph on Jupyter Notebook
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with PyQtGraph Part 6-Displaying a legend
Draw a "breast curved surface" in a 3D graph (2)
Read line by line from a file with Python
Draw multiple photos in a graph from multiple folders
[Python] How to draw a line graph with Matplotlib
Open Jupyter Lab (or Jupyter Notebook) by specifying a directory
[Python] Delete by specifying a tag with Beautiful Soup
Draw a graph with PyQtGraph Part 2--Detailed plot settings
Data visualization with Python-It's too convenient to draw a graph by attribute with "Facet" at once
Draw graph in python
Create a partial correlation matrix and draw an independent graph
Study math with Python: Draw a sympy (scipy) graph with matplotlib
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
[Visualization] I want to draw a beautiful graph with Plotly