Reputation: 383
I'm editing some old software that runs on Fortran and uses gnuplot. I'm trying to port some parts over to python and I'm a bit confused.
I have a matrix file of Hurricane data and it plots with the command:
plot 'file.txt' matrix with image 1:999:1:480 w l t ""
I don't fully understand the gnuplot command so when I use the plot function with matplotlib I get something totally different.
Anyone have an idea how I can plot this the same way in python?
Upvotes: 1
Views: 1497
Reputation: 2838
I agree with Christoph: your probable gnuplot command line is close to:
plot 'file.txt' matrix with image every 1:999:1:480 t ""
The plot
specifications with image
and with line
are in conflict.
Gnuplot is a lover of lazines. Or you hate it or you love it :-)
You can always find shortened the commands:
plot ---> pl
with ---> w
lines ---> l
title ---> t
and so on...
In Python you can try with something like (it remains to filter data if it misses the every
word in your command line...)
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# Read in data from an ASCII data table
data = np.genfromtxt('data.txt')
ax.imshow(data, cmap=plt.cm.gray, interpolation='nearest')
#ax.imshow(data, cmap=plt.cm.gray)
ax.set_title('My Title')
plt.show()
It reproduces the effect of the gnuplot example for help image
In data.txt
file I put the same data of the example
5 4 3 1 0
2 2 0 0 1
0 0 0 1 0
0 1 2 4 3
Upvotes: 3