我有一个'x'列(x_parameter)和多个'y'列(filtered_data),我正在尝试为每个x,y对生成一个散点图。我已成功完成以下功能:
def scatter_plot(self,filtered_data,x_parameter):
for i in range(len(filtered_data)):
if filtered_data[i].name==x_parameter:
x=filtered_data[i]
x_index=list(x.keys())
figure()
for i in range(len(filtered_data)):
y=filtered_data[i]
y_index=list(y.keys())
index_intersection = list(set(x_index)&set(y_index))
subplot(10,5,i)
scatter(x[index_intersection],y[index_intersection])
这会生成一个包含43个子图的大数字。我现在正试图改变这一点,以便我生成3个较小的数字,其中包含两个4x4子图,其余部分在最后。我还希望这个函数是动态的,并且能够处理任何大小的任何输入,并且仍然返回16个子图的数字“单位”和剩余数字。我这样做的尝试如下:
def scatter_plot(self,filtered_data,x_parameter):
number_of_full_subplots=len(filtered)/16
remainder=len(filtered)-(number_of_full_subplots*16)
for i in range(len(filtered_data)):
if filtered_data[i].name==x_parameter:
x=filtered_data[i]
x_index=list(x.keys())
for j in range(number_of_full_subplots+1):
figure(j)
for i in range(len(filtered_data)):
y=filtered_data[i]
y_index=list(y.keys())
index_intersection = list(set(x_index)&set(y_index))
x_to_plot=x[index_intersection]
y_to_plot=y[index_intersection]
for k in range(16):
plt.subplot(4,4,k)
plt.scatter(x_to_plot,y_to_plot)
然而,这产生3个适当大小的数字,但每个空间中具有相同的图形。有人能发现我的错误吗?
以下是'filtered_data'变量的示例。它是由另一个函数创建的,是一个大熊猫系列列表。对于每个x和y对,如果索引出现在两个系列中,我只绘制数据。
Name: RAR activation, dtype: float64, 0 168.806000
2 160.569000
4 175.428000
6 67.584900
7 218.879000
9 2.542630
11 1.822950
12 1.684010
14 0.818888
15 0.032629
21 0.001601
23 192.563000
Name: RAR deactivation, dtype: float64, 6 30.6522
7 30.7873
8 30.8454
9 30.9947
10 31.0030
11 31.1428
12 31.1922
13 31.2839
14 31.3500
15 31.5069
16 31.5113
17 31.5594
Name: Best Value, dtype: float64]
谢谢
答案 0 :(得分:0)
def scatter_x_y(self,filtered_data,x_parameter,y_parameter):
for i in range(len(filtered_data)):
if filtered_data[i].name==x_parameter:
x=filtered_data[i]
x_index=list(x.keys())
elif filtered_data[i].name==y_parameter:
y=filtered_data[i]
y_index=list(y.keys())
index_intersection=list(set(x_index)&set(y_index))
plt.figure
plt.scatter(x[index_intersection],y[index_intersection])
plt.title('{} Versus {}'.format(x.name,y.name))
def scatter_x_yi(self,filtered_data,x_parameter):
PE=Parameter_Estimation_Tools()
number_of_full_subplots=len(filtered_data)/16
remainder=len(filtered)-(number_of_full_subplots*16)-1
yi=[]
for i in range(len(filtered_data)):
if filtered_data[i].name!=x_parameter:
yi.append(filtered_data[i])
try:
for i in range(len(filtered_data)):
for j in range(number_of_full_subplots+1):
plt.figure(j)
for k in range(16):
plt.subplot(4,4,k)
PE.scatter_x_y(filtered_data,x_parameter,yi[16*j+k].name)
except IndexError:
print '{} has been plotted against all other parameters'.format(x_parameter)