I have an 'x' column (x_parameter) and multiple 'y' columns (filtered_data) and I'm trying to produce a scatter plot for each x,y pair. I have done this successfully in the following function:
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])
This produces one large figure with 43 sublots. I am now trying to change this so that I produce 3 smaller figures with two 4x4 subplots and the remainder in the last. I would also like this function to be dynamic and be able to handle any inputs of any size and still return figure 'units' of 16 subplots and a remainder figure. My attempt at doing this is below:
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)
However this produces 3 figures of the appropiate size but with the same graph in each space. Could anybody spot my mistake?
Here is an example of the 'filtered_data' variable. It was created by another function and is a list of pandas series. For each x and y pair I only plot the data if the indices appear in both series.
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]
Thanks
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.