Python 使用自定义记号标签打印矩阵数据

Python 使用自定义记号标签打印矩阵数据,python,matplotlib,imshow,Python,Matplotlib,Imshow,为了建立以X轴为P0、P1、P2等,Y轴为C0、C1、C2等,点为值的绘图。。我写了以下脚本 C0 C5 C10 C15 C20 C25 C30 C35 C40 C45 C50 P0 47.943345 44.914156 42.376835 37.2786 39.362123 29.822127

为了建立以X轴为P0、P1、P2等,Y轴为C0、C1、C2等,点为值的绘图。。我写了以下脚本

    C0           C5            C10         C15            C20   C25           C30            C35        C40       C45      C50
P0  47.943345   44.914156   42.376835   37.2786     39.362123   29.822127   29.629069   24.476678   25.052778   25.912881   24.902693
P1  52.682668   52.690758   41.695393   40.427713   41.858335   35.949049   31.22806    28.764532   44.168688   26.438761   30.69287
P2  83.258359   77.803689   73.910762   58.785376   64.709102   71.70526    43.322047   61.934794   37.209905   40.378957   34.300727
P3  84.759114   71.527146   67.49678    70.464186   70.525976   83.271145   54.537616   66.646541   50.066344   45.546549   36.019721
P4  93.104746   83.602079   99.354394   79.144163   91.973071   70.720547   71.314275   60.390247   77.29477    55.319029   49.143297
P5  118.607862  97.718288   93.90805    79.864234   93.758891   74.889755   72.362807   72.517549   51.188231   82.265352   62.780176
P6  115.568743  113.73798   102.607865  92.834522   87.443449   86.866084   69.150371   82.483823   94.319968   68.883143   58.444044

我到底犯了什么错误?如何构建一个?

我想这就是您想要做的:

temp = [[random.randint(0,200), random.randint(0,200), random.randint(0,200)], [random.randint(0,200), random.randint(0,200), random.randint(0,200)], [random.randint(0,200), random.randint(0,200), random.randint(0,200)]]
    plt.subplot(111)
    plt.title("error",fontsize=14)
    plt.xlabel("P",fontsize=12)
    plt.ylabel("CL",fontsize=12)
    plt.grid(True,linestyle='-',color='0.75')
    x = ['P0', 'P1','P2']
    y = ['C0','C1','C2']
    z = temp
    # scatter with colormap mapping to z value
    plt.scatter(x,y,s=20,c=z, marker = 'o', cmap = cm.jet );
    plt.colorbar()
    plt.gray()
    error = "error-graph.png"
    plt.savefig(error, bbox_inches='tight', pad_inches=0.2)

plt.scatter
正在寻找要绘制的(x,y)数值。您已经给了它点“('P0','C0'),('P1','C1'),('P2','C2'),它们是一对字符串。它无法描绘这个。您应该阅读并查看一些示例@是的,OP没有正确解释他想要什么,我编辑了这个问题。
import matplotlib.pyplot as plt
import numpy as np

grid = np.random.rand(4, 4)
x = ['P0', 'P1', 'P2', 'P4']
y = ['C0', 'C1', 'C2', 'C4']
plt.imshow(grid, interpolation='none')
plt.xticks(range(len(x)), x, fontsize=12)
plt.yticks(range(len(y)), y, fontsize=12)