散点图ValueError:x和y的大小必须相同

时间:2020-02-26 20:43:31

标签: python numpy matplotlib

import statistics
import numpy as np
states = [(d['State']) for d in data]
common_list=Counter(states).most_common(3)
first_common_temp=[d["Temperature(F)"] for d in data if d["State"] == common_list[0][0]]
FCT=[]
first_common_humid=[d["Humidity(%)"] for d in data if d["State"] == common_list[0][0]]
FCH=[]
second_common_temp=[d["Temperature(F)"] for d in data if d["State"] == common_list[1][0]]
SCT=[]
second_common_humid=[d["Humidity(%)"] for d in data if d["State"] == common_list[1][0]]
SCH=[]
third_common_temp=[d["Temperature(F)"] for d in data if d["State"] == common_list[2][0]]
TCT=[]
third_common_humid=[d["Humidity(%)"] for d in data if d["State"] == common_list[2][0]]
TCH=[]
#create six lists, three most common accident states and their corrosponding temp and humidity at time of accident, creates empty list to be filled with floats
x=0
for x in range (0, len(first_common_temp)):
    try:
        FCT.append(float(first_common_temp[x]))
    except ValueError:
        x=0
for x in range (0, len(first_common_humid)):
    try:
        FCH.append(float(first_common_humid[x]))
    except ValueError:
        x=0
for x in range (0, len(second_common_temp)):
    try:
        SCT.append(float(second_common_temp[x]))
    except ValueError:
        x=0
for x in range (0, len(second_common_humid)):
    try:
        SCH.append(float(second_common_humid[x]))
    except ValueError:
        x=0
for x in range (0, len(third_common_temp)):
    try:
        TCT.append(float(third_common_temp[x]))
    except ValueError:
        x=0
for x in range (0, len(third_common_humid)):
    try:
        TCH.append(float(third_common_humid[x]))
    except ValueError:
        x=0
#this is to make a usable list of just the filled data points, empty sets are removed
plt.figure(figsize=(16,8))
plt.subplot(1,3,1)
plt.scatter(FCH, FCT,
           s=100,
           #size
           c="red",
           marker=".",
           alpha=0.5
           #transparency
           )

我正在尝试使用有一些空数据的数据来绘制散点图,因此for循环创建了一个新列表,FTH和FCT的长度是一维的,但是随着FCT变大5而有所不同,但是我无法想象我需要缩短一个?

0 个答案:

没有答案