plt.图标题为的()给出错误:以10为基数的int()的文本无效

2024-04-25 19:59:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python2.6.5上运行以下简单的示例代码时,我遇到了一个问题。 我已经研究过无效文本问题的其他解决方案,在我看来,当python假定它正在绘制的数据是整数并试图迭代数据时,通常会出现这种情况。然而,在创建figure对象之前,这个错误似乎已经到达了。我可能错了,希望有人能给我指明正确的方向。在

import matplotlib.pyplot as plt
import numpy as np
x=np.array([1,2,3,4,5,6,7])
y=np.sin(x)
fig = plt.figure('test figure')
sub1=fig.add_subplot(1,1,1)
sub1.plot(x,y)

生成以下错误

^{pr2}$

根据评论添加

我使用的是matplotlib版本0.99.3rc1


Tags: 数据代码文本import示例matplotlibas错误
1条回答
网友
1楼 · 发布于 2024-04-25 19:59:32

您试图访问的功能正在传入a text label as ^{}。原来你只能在这里放一个数字,现在你可以放一个数字或字符串标签。在

此功能自2011年6月this commit开始提供。它的第一个版本是version 1.1.0。你说你使用的是0.99.3rc2版本,所以该功能将不可用。我最好的建议是升级(相当老!)除非有很强的理由不这么做。在


详情

允许您传递字符串代替整数位数的代码行是here,下面复制了一小段代码来说明这一点,matplotlib.pyplot.figure()的第一个参数命名为num,默认为None

#snippet from matplotlib.pyplot.figure()

if num is None:
    num = next_num
elif is_string_like(num):
    figLabel = num
    allLabels = get_figlabels()
    if figLabel not in allLabels:
        if figLabel == 'all':
            warnings.warn("close('all') closes all existing figures")
        num = next_num
    else:
        inum = allLabels.index(figLabel)
        num = allnums[inum]

相关问题 更多 >