【发布时间】:2015-07-17 19:31:18
【问题描述】:
我有一个“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]
谢谢
【问题讨论】:
标签: python matplotlib