Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.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 键?下的matplotlib图例标签;_Python_Matplotlib - Fatal编程技术网

Python 键?下的matplotlib图例标签;

Python 键?下的matplotlib图例标签;,python,matplotlib,Python,Matplotlib,如何调整与键相关的标签位置?我重新分类了数据,并显示了一个离散的corbar,看起来像多手柄图例。实际上,我找不到关于标签位置(文本或数字)的任何参数。默认设置为左键右键。我能换个位置吗?例如,键下方或上方的标签。我的目的是按如下方式显示图例(键下有标签,键之间没有空格): 似乎没有参数来调整标签的位置。将matplotlib.pyplot导入为plt 将numpy作为np导入 data=np.random.randint(8,size=(100100)) cmap=plt.cm.get_cm

如何调整与键相关的标签位置?我重新分类了数据,并显示了一个离散的corbar,看起来像多手柄图例。实际上,我找不到关于标签位置(文本或数字)的任何参数。默认设置为左键右键。我能换个位置吗?例如,键下方或上方的标签。我的目的是按如下方式显示图例(键下有标签,键之间没有空格):

似乎没有参数来调整标签的位置。

将matplotlib.pyplot导入为plt
将numpy作为np导入
data=np.random.randint(8,size=(100100))
cmap=plt.cm.get_cmap('PiYG',8)
图,ax=plt.子批次()
pcm=ax.pcolormesh(数据,cmap=cmap,alpha=0.75,vmin=0,vmax=8)
图颜色条(pcm,ax=ax)
plt.show()

导入matplotlib.pyplot作为plt
将numpy作为np导入
data=np.random.randint(8,size=(100100))
cmap=plt.cm.get_cmap('PiYG',8)
图,ax=plt.子批次()
pcm=ax.pcolormesh(数据,cmap=cmap,alpha=0.75,vmin=0,vmax=8)
图颜色条(pcm,ax=ax)
plt.show()

图片中的键在matplotlib中称为colorbar。是的,它是离散的colorbar,我将添加细节。图片中的键在matplotlib中称为colorbar。是的,它是离散的colorbar,我将添加细节。
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np

data  = np.random.randint(8, size=(100,100))
cmap = plt.cm.get_cmap('PiYG', 8) 
plt.pcolormesh(data,cmap = cmap,alpha = 0.75)
# Set borders in the interval [0, 1]
bound = np.linspace(0, 1, 9)
# Preparing borders for the legend
bound_prep = np.round(bound * 7, 2)
# Creating 8 Patch instances
plt.legend([mpatches.Patch(color=cmap(b)) for b in bound[:-1]],
       ['{}'.format(bound_prep[i]) for i in range(8)],
       bbox_to_anchor=(0,-0.25,1,0.2),ncol=len(bound))