Create a 2D plot with matplotlib. Even if the display is slow with gnuplot (1000x1000), it works with a margin.
What we call a two-dimensional plot here is It is a figure that displays the scalar quantity f (x, y) at the coordinates (x, y).
import numpy
from matplotlib import pyplot
data = numpy.random.rand(128,128) #128x128 2D numpy.Generate by putting random numbers in array
pyplot.imshow(data)
For the time being, if you have a 2D numpy.array, this is OK. However, index is used for the x / y axis.
grid
Use meshgrid
, pcolor
to get the grid.
from numpy import arange, meshgrid
from math import pi
from matplotlib import pyplot
x = arange(0,2*pi,2*pi/128)
y = arange(0,2*pi,2*pi/128)
X, Y = meshgrid(x,y)
data = numpy.random.rand(128,128)
pyplot.pcolor(X, Y, data)
In this case x / y can be log
pyplot.xscale("log")
norm Use the norm argument to logarithmic colors
from matplotlib.colors import LogNorm
...
pyplot.imshow(data, norm=LogNorm(vmin, vmax))
pyplot.pcolor(X, Y, data, norm=LogNorm(vmin, vmax))
vmin and vmax are the lower and upper limits, respectively. Automatic judgment if omitted or None
Recommended Posts