3
    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

为了构建 xaxis 作为 P0、P1、P2 等,Y 轴作为 C0、C1、C2 等以及点作为值的绘图。我编写了以下脚本

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)

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

4

1 回答 1

4

我认为这是你想要做的:

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)

在此处输入图像描述

于 2014-10-02T16:54:14.383 回答