In imshow with matplotlib () plotted as a function

matplotlib python is the most famous 2D graphics library that provides a set of command and matlab similar API, to be very suitable for interactive mapping. But it may also be convenient to control as the drawing, the embedded GUI applications. Statements by simple drawing, you can draw a high-quality FIG.

Here we talk about the main inshow () function is used.

First, look at how basic drawing process:

import matplotlib.pyplot as plt 

#创建新的figure
fig = plt.figure()

#必须通过add_subplot()创建一个或多个绘图
ax = fig.add_subplot(221)

#绘制2x2两行两列共四个图,编号从1开始
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)

#图片的显示
plt.show()

Screenshot follows:
Here Insert Picture Description
heatmap (HeatMap) is a common method of data analysis, to show difference data by color, brightness, easy to understand. In Matplotlib Python library, call imshow () function to achieve thermal mapping.

#coding=utf-8
import matplotlib.pyplot as plt 
import numpy as np

points = np.arange(-5,5,0.01)

xs,ys = np.meshgrid(points,points)

z = np.sqrt(xs**2 + ys**2)

#创建新的figure
fig = plt.figure()

#绘制2x2两行两列共四个图,编号从1开始
ax = fig.add_subplot(221)
ax.imshow(z)

ax = fig.add_subplot(222)
#使用自定义的colormap(灰度图)
ax.imshow(z,cmap=plt.cm.gray)

ax = fig.add_subplot(223)
#使用自定义的colormap
ax.imshow(z,cmap=plt.cm.cool)

ax = fig.add_subplot(224)
#使用自定义的colormap
ax.imshow(z,cmap=plt.cm.hot)

#图片的显示
plt.show()

Output:
Here Insert Picture Description
Error Memo:

问题一: NameError: name 'imshow' is not defined

Solution: Add in the file,

from pylab import *

Second problem: ImportError: No module named _internal

Solution: The reason is installed and the subsequent installation of a pip pip, leading to version conflicts.

Solution:
Follow-up and installation of a pip, leading to version conflicts.

Solution:

sudo apt remove python-pip

Guess you like

Origin www.cnblogs.com/xxpythonxx/p/12583942.html