python很坐标报错ufunc ‘isfinite‘ not supported for the input types

python使用plt画图的时候,出错。

出错全文如下:

Traceback (most recent call last):

    plt.show()
    return _get_backend_mod().show(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 __call__
    manager.show(**kwargs)
    self.canvas.show()
    FigureCanvasAgg.draw(self)
    self.figure.draw(self.renderer)
    result = draw(artist, renderer, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
    mimage._draw_list_compositing_images(
    a.draw(renderer)
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
    mimage._draw_list_compositing_images(
    a.draw(renderer)
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
    ticks_to_draw = self._update_ticks()
      
    minor_locs = self.get_minorticklocs()
                 ^^^^^^^^^^^^^^^^^^^^^^^^
    mask = np.isclose(tr_minor_locs[:, None], tr_major_locs[None, :],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    yfin = isfinite(y)
           ^^^^^^^^^^^
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Process finished with exit code 1

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'

报错原因:

作图的时候有不是数值类型的元素出现在图中。

比如plt默认横纵坐标都需要是数值型,中间的数据也需要是数值型。而你使用了其他类型。

比如:

python绘制对应的折线图或者柱状图的时候,我们有时候希望横坐标是一些固定的文字,而不是标准的数值坐标。

希望将横坐标的12345,改成下面的字符。

需要用到的程序:

labels = ['1K','10K','100K','1M','10M']
plt.xticks(selected_data.iloc[:,0], labels,fontsize= fontsize) 

以上代码就是报错。

需要将代码改成下面这样:

labels = ['1K','10K','100K','1M','10M']
positions = selected_data.iloc[:,0].tolist()
plt.xticks(positions , labels,fontsize= fontsize)  #使得标签现实的是给定的文字标签

OK

相关推荐

  1. Python:sqlalchemyDetachedInstanceError

    2024-04-03 11:16:04       34 阅读
  2. python 问题汇总

    2024-04-03 11:16:04       21 阅读
  3. python opencv运行

    2024-04-03 11:16:04       10 阅读
  4. Python调用pyspark整理

    2024-04-03 11:16:04       35 阅读
  5. pythonunable to rollback pymysql

    2024-04-03 11:16:04       17 阅读
  6. mac执行python3 --version

    2024-04-03 11:16:04       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 11:16:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 11:16:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 11:16:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 11:16:04       20 阅读

热门阅读

  1. RuoYi单体版Table行内编辑

    2024-04-03 11:16:04       16 阅读
  2. 研究应用推广开源项目——提高软件技术的途径

    2024-04-03 11:16:04       15 阅读
  3. LTP测试工具

    2024-04-03 11:16:04       14 阅读
  4. 对seata的seata.tx-service-group理解

    2024-04-03 11:16:04       12 阅读
  5. c# 如何调用指定文件夹里面的动态库dll

    2024-04-03 11:16:04       14 阅读
  6. css设置宽高等比 设置和宽度一样的高度

    2024-04-03 11:16:04       15 阅读