Commit 3d718867 authored by amichaut's avatar amichaut
Browse files

minor plotting improvements and bug fixes

parent 87894c3e
This diff is collapsed.
This diff is collapsed.
......@@ -998,7 +998,7 @@ def plot_all_traj(data_dir, df, image={'image_fn': None, 't_dim': None, 'z_dim':
else:
stack = [] # stack to store images
groups = df.groupby('frame')
for frame in df['frame'].unique():
for frame in np.sort(df['frame'].unique()):
frame = int(frame)
fig = plot_traj(df, frame, data_dir, groups=groups, image=image, plot_dir=plot_dir,
traj_parameters=traj_parameters,
......@@ -1047,7 +1047,7 @@ def plot_all_scalar_fields(data_dir, df, data, field, image={'image_fn': None, '
plot_cmap(plot_dir, label, map_param_['cmap'], map_param_['vlim'][0], map_param_['vlim'][1],suffix='_'+field)
stack = [] # stack to store images
for frame in df['frame'].unique():
for frame in np.sort(df['frame'].unique()):
frame = int(frame)
fig = plot_scalar_field(data_dir, df, data, field, frame, image=image,
map_param=map_param_, plot_dir=plot_dir, plot_config=plot_config)
......@@ -1100,7 +1100,7 @@ def plot_all_vector_fields(data_dir, df, data, field, plot_on_field=None, dim=3,
plot_cmap(plot_dir, label, plot_on_field['cmap'], plot_on_field['vlim'][0], plot_on_field['vlim'][1],suffix='_vector_'+plot_on_field['plot_on'])
stack = [] # stack to store images
for frame in df['frame'].unique():
for frame in np.sort(df['frame'].unique()):
frame = int(frame)
fig = plot_vector_field(data_dir, df, data, field, frame, plot_on_field=plot_on_field, dim=dim, image=image,
map_param=map_param, plot_dir=plot_dir, plot_config=plot_config)
......@@ -1172,7 +1172,7 @@ def plot_all_Voronoi(data_dir, df, data, show_local_area=True, df_mean = None,
plot_cmap(plot_dir, label, map_param['cmap'], map_param['vlim'][0], map_param['vlim'][1],suffix='_area')
stack = [] # stack to store images
for frame in df['frame'].unique():
for frame in np.sort(df['frame'].unique()):
frame = int(frame)
fig = plot_Voronoi(data_dir, df, frame, data, show_local_area=show_local_area, image=image, map_param=map_param,
plot_dir=plot_dir, plot_config=plot_config, dont_print_count=dont_print_count)
......@@ -1302,8 +1302,9 @@ def plot_all_MSD(data_dir, df=None, df_out=None, fit_model="biased_diff", msd_al
lab = 'mean' if hue is None else hue_order[j]
suffix = '' if hue is None else '_' + hue_order[j]
color_mean = 'k' if len(msd_all_list)==1 else color_list[j]
msd_mean.plot(x="tau", y="msd_mean", color=color_list[j], ax=ax, label=lab)
msd_mean.plot(x="tau", y="msd_mean", color=color_mean, ax=ax, label=lab)
msd_mean.to_csv(osp.join(plot_dir, 'all_MSD_mean' + suffix + '.csv'))
# calculate exponent
msd_mean[['tau', 'msd_mean']] = msd_mean[['tau', 'msd_mean']].astype(np.float64)
......@@ -1375,6 +1376,8 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
cmap = specific_config['cmap']
cmap_lim = specific_config['cmap_lim']
subset_order = specific_config['subset_order']
transparency = specific_config['transparency']
show_legend = True
# get info
info = tpr.get_info(data_dir)
......@@ -1399,7 +1402,7 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
cmap_lim = [df['z_scaled'].min(), df['z_scaled'].max()]
if len(cmap_lim) == 2:
plot_cmap(plot_dir, tpr.make_param_label('z', l_unit=info["length_unit"]), cmap, cmap_lim[0], cmap_lim[1],suffix='_total_traj')
plot_cmap(plot_dir, tpr.make_param_label('z_scaled', l_unit=info["length_unit"]), cmap, cmap_lim[0], cmap_lim[1],suffix='_total_traj')
elif color_code == 't':
if cmap_lim is None:
......@@ -1424,6 +1427,7 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
elif dim == 2 and color_code == 'z':
color_code == 'random'
label_list = [] # to store label that have already been used
fig, ax = plt.subplots(1, 1, figsize=plot_config['figsize'])
for i, track in enumerate(df['track'].unique()):
traj = tpr.get_traj(track_groups, track)
......@@ -1440,6 +1444,7 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
traj['y_scaled'] -= y0
# color code
label = None
if color_code == "z":
colors = tpr.get_cmap_color(z, cmap, vmin=cmap_lim[0], vmax=cmap_lim[1])
elif color_code == "t":
......@@ -1451,6 +1456,10 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
elif color_code == "group":
if 'subset_order' in df.columns:
colors = color_list[traj['subset_order'].values[0] % len(color_list)]
subset = df[df['track']==track]['subset'].values[0]
if subset not in label_list:
label = subset
label_list.append(subset)
else:
colors = color_list[0] # if color_coded by subset but there's none, use only one color
else:
......@@ -1459,11 +1468,11 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
if traj_length > 1: # dont plot single points
if color_code == 'z' or color_code == "t":
for j in range(1, traj_length):
ax.plot([x[j - 1], x[j]], [y[j - 1], y[j]], ls='-', color=colors[j])
ax.plot(x[-1], y[-1], marker='.', color=colors[-1])
ax.plot([x[j - 1], x[j]], [y[j - 1], y[j]], ls='-', color=colors[j],alpha=transparency)
ax.plot(x[-1], y[-1], marker='.', color=colors[-1],alpha=transparency)
else:
ax.plot(x, y, ls='-', color=colors)
ax.plot(x[-1], y[-1], marker='.', color=colors)
ax.plot(x, y, ls='-', color=colors,alpha=transparency,label=label)
ax.plot(x[-1], y[-1], marker='.', color=colors,alpha=transparency)
if hide_labels is False:
s = '{}'.format(int(track))
......@@ -1471,8 +1480,8 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
if set_axis_lim is not None:
ax.set_xlim(set_axis_lim[0], set_axis_lim[1])
ax.set_ylim(set_axis_lim[2], set_axis_lim[3])
ax.set_xlabel(r'x ($\mu m$)')
ax.set_ylabel(r'y ($\mu m$)')
ax.set_xlabel(tpr.make_param_label('x_scaled', l_unit=info["length_unit"]))
ax.set_ylabel(tpr.make_param_label('y_scaled', l_unit=info["length_unit"]))
if equal_axis:
ax.set_aspect('equal')
......@@ -1481,6 +1490,10 @@ def plot_total_traj(data_dir, df, dim=3, plot_dir=None, plot_fn=None, plot_confi
ylim = ax.get_ylim()
ax.set_ylim(ylim[1], ylim[0])
if show_legend:
if len(label_list) > 0:
ax.legend(frameon=False)
fig.tight_layout()
filename = osp.join(plot_dir,'total_traj'+plot_config['format']) if plot_fn is None else plot_fn
......
......@@ -957,7 +957,7 @@ def select_traj_by_xyzt(df, xlim=None, ylim=None, zlim=None, frame_lim=None):
:rtype: list
"""
# filter by frame subset
if type(frame_lim) is list:
if type(frame_lim) is list or type(frame_lim) is tuple:
df = filter_by_frame_subset(df, frame_subset=frame_lim)
elif type(frame_lim) is int or type(frame_lim) is float:
df = df[df['frame'] == frame_lim]
......@@ -1337,6 +1337,7 @@ def make_traj_config(data_dir=None, export_config=True):
'cmap': 'plasma', # colormap to be used if color_code is 'z'
'cmap_lim': None, # pass custom colormap limits
'subset_order': None, # if color_code is group, order of group in color cycle
'transparency': 1, #plot transparency
}
# config of voronoi plot
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment