Вопрос

I have a file 'data', which is formatted for splot in gnuplot.

x1 y1 z11
x1 y2 z12
... 
x1 yn z1n
...
xn yn-1 znn-1
xn yn znn

In gnuplot I use

set pm3d map
splot 'data' u 1:2:3

to produce a heatmap of my data.

How can I proceed to plot the same with python?

Это было полезно?

Решение

Suppose I have the columns x,y,z which have the format from above.

from numpy import *
from pylab import *

Z = z.reshape(nx,ny) # makes a (Zy,Zx) matrix out of z
T = Z.T              # transposes the matrix (Zx,Zy)

imshow(T, aspect='auto', origin='lower', extent = ( x.min(), x.max(), y.min(), y.max()))
show()

Does the job.

Другие советы

I am just starting to make the shift from gnuplot to python myself. Here is an example using matplotlib/numpy:

#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np

Z = np.arange(100).reshape(10,10)
plt.imshow(Z, interpolation='none')
plt.show()

You can create the Z matrix any way you like, but it should be a numpy array. The commands imshow and matshow are about the same in matplotlib, but matshow shows the data with the y-axis reversed and without interpolation by default.

I recommend looking at the options for imshow, especially extent which defines the x and y ranges.

This answer is also a good option, if you want to automatically define your extent.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top