Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;TypeError:列表索引必须是整数,而不是str";尝试将列表的索引绘制为直方图时_Python_Python 3.x_Matplotlib_Error Handling - Fatal编程技术网

Python &引用;TypeError:列表索引必须是整数,而不是str";尝试将列表的索引绘制为直方图时

Python &引用;TypeError:列表索引必须是整数,而不是str";尝试将列表的索引绘制为直方图时,python,python-3.x,matplotlib,error-handling,Python,Python 3.x,Matplotlib,Error Handling,我已经创建了一个包含蛋白质长度的列表,现在我正试图将所有蛋白质的长度绘制为一个带有50个箱子的直方图,但我总是得到以下错误: /usr/bin/python3.4 /root/PycharmProjects/Python_5/prog9.py /root/PycharmProjects/Python_5/unip-mini.dat.txt ['458', '156', '217', '352', '447', '347', '85', '751', '90', '225', '106', '17

我已经创建了一个包含蛋白质长度的列表,现在我正试图将所有蛋白质的长度绘制为一个带有50个箱子的直方图,但我总是得到以下错误:

/usr/bin/python3.4 /root/PycharmProjects/Python_5/prog9.py
/root/PycharmProjects/Python_5/unip-mini.dat.txt
['458', '156', '217', '352', '447', '347', '85', '751', '90', '225', '106', '178', '59', '337', '129', '144', '279', '100', '134', '253', '83', '122', '94', '116', '335', '65', '90', '123', '683', '142', '309', '283', '130', '236', '155', '232', '179', '280', '55', '230', '129', '156', '177', '158', '147', '241', '175', '162', '156', '50', '165', '98', '171', '118', '363', '85', '174', '122', '126', '124', '124', '141', '141', '141', '141', '141', '146', '146', '147', '146', '146', '234', '121', '60', '893', '924', '57', '57', '80', '104', '102', '275', '286', '302', '117', '169', '171', '157', '160', '120', '127', '130', '272', '270', '270', '269', '269', '269', '104', '113', '116', '104', '104', '125', '124', '124', '124', '124', '125', '82', '120', '121', '121', '118', '122', '118', '118', '118', '137', '125', '137', '137', '124', '124', '124', '124', '290', '290', '290', '296', '257', '68', '175', '61', '145', '95', '254', '68', '74', '126', '459', '493', '480', '120', '89', '67', '141', '139', '142', '236', '297', '105', '273', '235', '368', '29', '111', '24', '611', '201', '239', '71', '57', '114', '65', '14', '13', '565', '504', '538', '194', '64', '261', '84', '254', '252', '241', '268', '267', '248', '244', '244', '239', '261', '264', '80', '252', '249', '259', '259', '248', '248', '248', '238', '261', '262', '66', '214', '254', '254', '255', '236', '256', '10', '260', '267', '265', '28', '260', '268', '262', '255', '258', '248', '260', '258', '265', '257', '252', '248', '230', '261', '263', '261', '262', '257', '255', '261', '246', '244', '262', '246', '246', '246', '246', '246', '193', '247', '255', '261', '244', '258', '260', '261', '249', '255', '255', '262', '255', '255', '255', '255', '272', '246', '246', '246', '246', '258', '247', '247', '247', '247', '247', '247', '158', '248', '248', '248', '248', '245', '245', '245', '245', '245', '245', '245', '245', '61', '248', '247', '245', '245', '248', '245', '245', '245', '245', '245', '245', '245', '264', '259', '252', '277', '258', '251', '259', '259', '264', '266', '260', '260', '17', '220', '251', '262', '235', '244', '244', '244', '244', '242', '244', '247', '247', '248', '247', '247', '245', '414', '666', '137', '144', '124', '147', '147', '147', '147', '147', '147', '147', '147', '151', '57', '475', '53', '152', '264', '132', '43', '43', '43', '43', '179', '606', '184', '154', '154', '159', '159', '80', '159', '159', '159', '154', '154', '159', '154', '159', '159', '159', '215', '147', '149', '138', '140', '148', '73', '1707', '139', '365', '365', '365', '365', '365', '365', '365', '362', '365', '365', '365', '365', '365', '557', '460', '495', '488', '493', '493', '365', '487', '487', '492', '496', '475', '494', '485', '469', '474', '476', '470', '495', '447', '469', '470', '517', '473', '484', '491', '368', '338', '338', '337', '337', '337', '339', '339', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '338', '345', '338', '337', '338', '337', '338', '338', '338', '338', '338', '338', '338', '330', '329', '325', '338', '338', '338', '337', '339', '337', '338', '312', '338', '338', '341', '502', '501', '502', '618', '568', '580', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '365', '1126', '966', '961', '958', '993', '993', '993', '993', '993', '991', '993', '908', '1005', '962', '993', '1094', '362', '359', '365', '362', '362', '362', '363', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '362', '363', '362', '362', '362', '365', '366', '366', '365', '366', '366', '366', '366', '366', '366', '366', '366', '366', '366', '366', '366', '366', '366', '372', '366', '346', '235', '597', '596', '596', '595', '596', '602', '599', '600', '597', '362', '61', '152', '256', '1046', '390', '360', '160', '274', '193', '184', '56', '96', '63', '269', '176', '176', '193', '265', '73', '440', '22', '62', '170', '99', '126', '117', '54', '37', '141', '166', '336', '59', '258', '1361', '20', '71', '136', '148', '121', '315', '417', '236', '29', '152', '50', '184', '495', '486', '486', '499', '497', '500', '477', '602', '586', '757', '497', '467', '467', '165', '522', '524', '524', '524', '500', '510', '492', '546', '588', '590', '584', '591', '589', '589', '395', '589', '590', '635', '587', '601', '601', '602', '601', '587', '513', '508', '499', '447', '447', '447', '581', '426', '447', '447', '463', '526', '501', '443', '443', '443', '443', '443', '525', '525', '443', '443', '413', '443', '468', '443', '451', '453', '453', '453', '447', '447', '447', '447', '447', '548', '627', '54', '266', '266', '266', '266', '266', '266', '266', '266', '266', '266', '266', '266', '266', '110', '100', '255', '95', '205', '255', '30', '404', '347', '378', '328', '355', '355', '355', '355', '355', '355', '355', '355', '355', '355', '355', '357', '355', '374', '402', '164', '146', '133', '17', '20', '104', '148', '170', '154', '178', '155', '164', '125', '104', '166', '180', '100', '295', '141', '178', '186', '110', '172', '141', '61', '67', '258', '158', '44', '268', '268', '268', '268', '268', '154', '160', '160', '160', '160', '104', '104', '104', '182', '330', '331', '330', '330', '61', '74', '73', '92', '358', '232', '418', '69', '159', '37', '234', '173', '462', '69', '98', '10', '303', '298', '303', '270', '270', '356', '355', '356', '353', '353', '353', '353', '353', '351', '349', '350', '350', '353', '353', '353', '353', '357', '357', '357', '357', '276', '269', '271', '276', '276', '311', '352', '352', '352', '352', '148', '364', '362', '363', '356', '362', '362', '360', '364', '356', '360', '42', '364', '307', '364', '357', '362', '356', '351', '360', '356', '355', '355', '356', '356', '387', '382', '386', '375', '386', '60', '375', '375', '373', '375', '376', '319', '319', '319', '357', '319', '125', '319', '353', '352', '352', '542', '114', '93', '243', '165', '51', '40', '254', '347', '411', '254', '373', '373', '373', '373', '373', '372', '373', '373', '373', '373', '373', '373', '373', '373', '373', '373', '369', '369', '338', '373', '373', '370', '373', '373', '346', '346', '346', '61', '701', '601', '561', '559', '476', '385', '393', '392', '393', '373', '373', '455', '463', '457', '21', '21', '150', '153', '150', '152', '144', '150', '150', '150', '150', '147', '153', '150', '272', '150', '153', '154', '146', '146', '146', '145', '144', '153', '157', '168', '173', '155', '175', '152', '146', '146', '162', '158', '154', '175', '149', '158', '150', '246', '192', '192', '192', '192', '191', '188', '188', '179', '180', '189', '195', '179', '179', '179', '286', '177', '174', '174', '281', '281', '171', '186', '192', '176', '287', '182', '286', '180', '175', '184', '286', '272', '192', '180', '182', '169', '170', '185', '185', '189', '174', '286', '189', '180', '181', '176', '176', '176']
Traceback (most recent call last):
  File "/root/PycharmProjects/Python_5/prog9.py", line 67, in <module>
    main()
  File "/root/PycharmProjects/Python_5/prog9.py", line 34, in main
    x = seq[i]
TypeError: list indices must be integers, not str

您的程序中有错误的类型

替换:

for i in seq:
    x = seq[i]


这可能是因为您的
i
是字符串。尝试
x=seq[int(i)]
for i in seq:
    x = seq[i]
x = [int(i) for i in seq]