Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在热量表中显示单词。python_Python_Matplotlib - Fatal编程技术网

在热量表中显示单词。python

在热量表中显示单词。python,python,matplotlib,Python,Matplotlib,这是热图的代码。我想知道我是否可以更改字母的数字1、2、3、4,比如A、B、C、D,每个方块下面的每个字母 ''' Most heatmap tutorials I found online use pyplot.pcolormesh with random sets of data from Numpy; I just needed to plot x, y, z values stored in lists--without all the Numpy mumbo jumbo. Here I

这是热图的代码。我想知道我是否可以更改字母的数字1、2、3、4,比如A、B、C、D,每个方块下面的每个字母

'''
Most heatmap tutorials I found online use pyplot.pcolormesh with random sets of
data from Numpy; I just needed to plot x, y, z values stored in lists--without
all the Numpy mumbo jumbo. Here I have code to plot intensity on a 2D array, and
I only use Numpy where I need to (pcolormesh expects Numpy arrays as inputs).
'''
import matplotlib.pyplot as plt
import numpy as np

#here's our data to plot, all normal Python lists
x = [0, 1, 2, 3, 4,5]
y = [0, 1, 2, 3, 4,5]

intensity = [
    [5, 10, 15, 20, 25,3],
    [30, 35, 40, 45, 50,23],
    [55, 60, 65, 70, 75,34],
    [80, 85, 90, 95, 100,24],
    [105, 110, 115, 120, 125,23],
    [105, 110, 115, 120, 125,23]
]

#setup the 2D grid with Numpy
x, y = np.meshgrid(x, y)

#convert intensity (list of lists) to a numpy array for plotting
intensity = np.array(intensity)

#now just plug the data into pcolormesh, it's that easy!
plt.pcolormesh(x, y, intensity)
plt.colorbar() #need a colorbar to show the intensity scale
plt.show() #boom 

您将需要set_*ticklebals命令。设置强度后,我更改了您的代码,如下所示:

f, a = plt.subplots()
im = a.pcolormesh(x, y, intensity)
f.colorbar(im, ax = a) #need a colorbar to show the intensity scale
labels = [item.get_text() for item in a.get_xticklabels()]
labels = ['A', 'B', 'C', 'D', 'E', 'F']
a.set_xticklabels(labels) #set xtick
a.set_yticklabels(labels) #set ytick
plt.show() #boom 
如图所示:

f, a = plt.subplots()
im = a.pcolormesh(x, y, intensity)
f.colorbar(im, ax = a) #need a colorbar to show the intensity scale
labels = [item.get_text() for item in a.get_xticklabels()]
labels = ['A', 'B', 'C', 'D', 'E', 'F']
a.set_xticklabels(labels) #set xtick
a.set_yticklabels(labels) #set ytick
plt.show() #boom 

您将需要set_*ticklabels命令。设置强度后,我更改了您的代码,如下所示:

f, a = plt.subplots()
im = a.pcolormesh(x, y, intensity)
f.colorbar(im, ax = a) #need a colorbar to show the intensity scale
labels = [item.get_text() for item in a.get_xticklabels()]
labels = ['A', 'B', 'C', 'D', 'E', 'F']
a.set_xticklabels(labels) #set xtick
a.set_yticklabels(labels) #set ytick
plt.show() #boom 
如图所示:

f, a = plt.subplots()
im = a.pcolormesh(x, y, intensity)
f.colorbar(im, ax = a) #need a colorbar to show the intensity scale
labels = [item.get_text() for item in a.get_xticklabels()]
labels = ['A', 'B', 'C', 'D', 'E', 'F']
a.set_xticklabels(labels) #set xtick
a.set_yticklabels(labels) #set ytick
plt.show() #boom 

最简单、最直接的方法是
pyplot.xticks()
方法,该方法专门针对x轴上的标签:

x = [0, 1, 2, 3, 4, 5]
y = [0, 1, 2, 3, 4, 5]

# add these lines here    
x_ticks = ['', 'A', 'B', 'C', 'D', 'E']
plt.xticks(x, x_ticks)  
注意:第一个标签设置为空
'
以说明原点:


参考文档:

最简单、最直接的方法是
pyplot.xticks()
方法,该方法专门针对x轴上的标签:

x = [0, 1, 2, 3, 4, 5]
y = [0, 1, 2, 3, 4, 5]

# add these lines here    
x_ticks = ['', 'A', 'B', 'C', 'D', 'E']
plt.xticks(x, x_ticks)  
注意:第一个标签设置为空
'
以说明原点:

参考文件: