在你提供的代码中,你定义了x和y的数组。然而,x和y的长度不一致,导致出现"shape mismatch"错误。请确保x和y具有相同的长度,以解决此错误。

以下是一个修复代码的示例,其中x和y具有相同的长度(90):

import numpy as np
import matplotlib.pyplot as plt

plt.subplot(1, 1, 1)
fig = plt.figure()
plt.figure(figsize=(8, 6))
plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['axes.unicode_minus'] = False

x = np.arange(1, 91)
y = np.array([87600, 87420, 87260, 87120, 86970, 86840, 86700, 86560, 86430, 86300,
      86160, 86020, 85870, 85740, 85600,85470, 85340, 85200, 85060, 84920,
      84790, 84660, 84510, 84380, 84250, 84100, 83970, 83830, 83690, 83550,
      83420, 83280, 83140, 82990, 82860, 82710, 82570, 82440, 82310, 82180,
      82040, 81910, 81770, 81620, 81480,81350, 81220, 81090, 80940, 80810,
      80680, 80530, 80400, 80270, 80130, 79990, 79860, 79720, 79580, 79440,
      79310, 79180, 79050, 78910, 78780, 78650, 78490, 78360, 78230, 78100,
      77960, 77830, 77690, 77560, 77400,77270, 77140, 77010, 76870, 76740,
      76610, 76470, 76330, 76200, 77400, 77270, 77140, 77010, 76870, 76740])

plt.bar(x, y, width=0.5, align="center", label="Capacity")
plt.title("Capacity", loc="center")
for a, b in zip(x, y):
    plt.text(a, b, b, ha='center', va='center', fontsize=12)

plt.ylabel("区域")
plt.xlabel("任务量")
plt.legend()
# plt.savefig(r"C:\2.jpg")
plt.show()

这段修复后的代码将不再引发"shape mismatch"错误,并正确绘制条形图。

用python完成以下需求请示例代码 import numpy as np import matplotlibpyplot as plt pltsubplot1 1 1 fig = pltfigure pltfigurefigsize=8 6 pltrcParamsfontsans-serif = KaiTi pltrcParamsaxesunicode_mi

原文地址: https://www.cveoy.top/t/topic/jdZ9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录