[PYTHON] 2D plot in matplotlib

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).

Basic edition

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

2D plot in matplotlib
3D plot with matplotlib
Specify the color in the matplotlib 2D map
Put matplotlib in Centos7.
2-axis plot with Matplotlib
View images in Matplotlib
Create 3D scatter plot with SciPy + matplotlib (Python)
Time series plot / Matplotlib
How to add color bars in matplotlib bar plot
Embed matplotlib graphs in Tkinter
Solve ABC175 D in Python
Stackable bar plot with matplotlib
Plot geographic information in Python
Interactive plot of 3D graph
Notes on coloring by value in the matplotlib scatter plot
Create plot animation with Python + Matplotlib
Show axes as percentages in Matplotlib
Draw retention rate graph in Matplotlib
Heatmap with Dendrogram in Python + matplotlib
3D drawing with SceneKit in Pythonista
Make matplotlib Japanese compatible in 3 minutes
Show dividing lines in matplotlib histogram
Continuously color with matplotlib scatter plot
Cases using pandas plot, cases using (pure) matplotlib plot
Lognormal probability plot with Python, matplotlib
The first step in Python Matplotlib
How to display legend marks in one with Python 2D plot
Plot CSV of time series data with unixtime value in Python (matplotlib)
Watershed method in 3D images using ImageJ
Display LaTeX notation formulas in Python, matplotlib
[Python, Julia] 3D display in Jupyter-Mayavi library
How to suppress display error in matplotlib
Displaying candlestick charts in Python (matplotlib edition)
Summary of frequently used commands in matplotlib
ABC 157 D --Solve Friend Suggestions in Python!
Display matplotlib diagrams in a web application
Jupyter, numpy, matplotlib notes used in reports
Display Matplotlib xy graph in PySimple GUI.
Don't use \ d in Python 3 regular expressions!
Separation of design and data in matplotlib
Solve ABC165 A, B, D in Python
I want to embed Matplotlib in PySimpleGUI
Working with 3D data structures in pandas
Why can't I install matplotlib in python! !!
The date is displayed incorrectly in matplotlib.
[Scientific / technical calculation by Python] Plot, visualize, matplotlib 2D data with error bars