【问题标题】:problem when using rotation of xticks in matplotlib在 matplotlib 中使用 xticks 旋转时出现问题
【发布时间】:2022-01-26 02:25:38
【问题描述】:

当我尝试在 jupyter notebook 上运行此代码时,出现“类型错误:int object is not callable”,此代码的先前步骤如下: 1-我已将 matplotlib.pyplot 作为 plt 以及 pandas 作为 pd 导入 2- 将 x 定义为一系列字符串数据类型 3- 将 y 定义为数值数据类型 代码如下:

plt.figure(figsize=(9, 6))

x = data_used_cars["Brand"]
y = data_used_cars["Cars Listings"]

plt.bar(x=x, height=y)
plt.xticks(rotation=45)
plt.show()

数据集:

Brand Cars Listings
Audi 419
BMW 636
Mercedes-Benz 820
Mitsubishi 306
Renault 438
Toyota 509
Volkswagen 875

希望我能找到解决办法

【问题讨论】:

  • 代码调用正确。 xy 变量中的内容是什么?我认为问题出在某个地方。
  • x是字符串数据类型,y是"int64",x代表车种,y是频率,这个问题让我头疼,搞不清楚原因
  • 我附上了一张显示使用的数据集的图片

标签: python matplotlib rotation data-analysis


【解决方案1】:

将 matplotlib 库升级到 3.5.1 版本解决了问题

【讨论】:

    猜你喜欢
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    相关资源
    最近更新 更多