Commit b931d225 authored by Somnath, Suhas's avatar Somnath, Suhas Committed by GitHub
Browse files

Merge pull request #118 from pycroscopy/cades_dev

Improvements to plotting esp GIV
parents 181619f5 7aae4516
......@@ -180,7 +180,7 @@ def do_bayesian_inference(V, IV_point, freq, num_x_steps=251, gam=0.03, e=10.0,
return results_dict
def plot_bayesian_spot_from_h5(h5_bayesian_grp, h5_resh, pix_ind, r_extra_override=None):
def plot_bayesian_spot_from_h5(h5_bayesian_grp, h5_resh, pix_ind, r_extra_override=None, **kwargs):
"""
Plots the basic Bayesian Inference results for a specific pixel
......@@ -227,11 +227,11 @@ def plot_bayesian_spot_from_h5(h5_bayesian_grp, h5_resh, pix_ind, r_extra_overri
cap_val = h5_cap[pix_ind]
return plot_bayesian_results(orig_bias, possibly_rolled_bias, i_meas, bias_interp, mr_vec, i_recon, vr_vec,
split_directions, cap_val, freq, r_extra, pix_pos=h5_pos[pix_ind])
split_directions, cap_val, freq, r_extra, pix_pos=h5_pos[pix_ind], **kwargs)
def plot_bayesian_results(orig_bias, possibly_rolled_bias, i_meas, bias_interp, mr_vec, i_recon, vr_vec,
split_directions, cap_val, freq, r_extra, pix_pos=[0, 0]):
split_directions, cap_val, freq, r_extra, pix_pos=[0, 0], broken_resistance=True, **kwargs):
"""
Plots the basic Bayesian Inference results for a specific pixel
......@@ -261,12 +261,15 @@ def plot_bayesian_results(orig_bias, possibly_rolled_bias, i_meas, bias_interp,
Resistance of extra resistor [Ohms] necessary to get correct resistance values
pix_pos : list of two numbers
Pixel row and column positions or values
broken_resistance : bool, Optional
Whether or not to break the resistance plots into sections so as to avoid plotting areas with high variance
Returns
-------
fig : matplotlib.pyplot figure handle
Handle to figure
"""
font_size_1 = 14
font_size_2 = 16
......@@ -302,7 +305,7 @@ def plot_bayesian_results(orig_bias, possibly_rolled_bias, i_meas, bias_interp,
fig, axes = plt.subplots(ncols=3, figsize=(15, 5))
# fig.subplots_adjust(wspace=3.5)
axes[0].set_ylabel('Resistance (G\Omega)', fontsize=font_size_2)
axes[0].set_ylabel('Resistance (G$\Omega$)', fontsize=font_size_2)
if split_directions:
pts_to_plot = [good_forw, good_rev]
......@@ -314,14 +317,32 @@ def plot_bayesian_results(orig_bias, possibly_rolled_bias, i_meas, bias_interp,
colors, syms, names):
axis.set_title('$R(V)$ ' + set_name + ' at Row = ' + str(pix_pos[0]) +
' Col =' + str(pix_pos[1]), fontsize=font_size_2)
axis.plot(bias_interp[pts_list], mr_vec[pts_list], cols_set[0],
linestyle=sym_set[0], linewidth=3, label='R(V)')
axis.fill_between(bias_interp[pts_list], pos_limits[pts_list], neg_limits[pts_list],
alpha=0.25, color=cols_set[1],
label='R(V)+-$\sigma$')
single_plot = not broken_resistance
if broken_resistance:
diff = np.diff(pts_list)
jump_inds = np.argwhere(diff > 4) + 1
if jump_inds.size < 1:
single_plot = True
if not single_plot:
jump_inds = np.append(np.append(0, jump_inds), pts_list[-1])
for ind in range(1, jump_inds.size):
cur_range = pts_list[jump_inds[ind - 1]:jump_inds[ind]]
axis.plot(bias_interp[cur_range], mr_vec[cur_range], cols_set[0],
linestyle=sym_set[0], linewidth=3)
axis.fill_between(bias_interp[cur_range], pos_limits[cur_range], neg_limits[cur_range],
alpha=0.25, color=cols_set[1])
if ind == 1:
axis.legend(['R(V)', 'R(V)+-$\sigma$'], loc='upper left', fontsize=font_size_1)
else:
axis.plot(bias_interp[pts_list], mr_vec[pts_list], cols_set[0],
linestyle=sym_set[0], linewidth=3, label='R(V)')
axis.fill_between(bias_interp[pts_list], pos_limits[pts_list], neg_limits[pts_list],
alpha=0.25, color=cols_set[1], label='R(V)+-$\sigma$')
axis.legend(loc='upper left', fontsize=font_size_1)
axis.set_xlabel('Voltage (V)', fontsize=font_size_2)
axis.legend(loc='upper left', fontsize=font_size_1)
axis.set_xlim((-ex_amp, ex_amp))
# ################### CURRENT PLOT ##########################
......
......@@ -365,6 +365,74 @@ def plot_map(axis, data, stdevs=2, origin='lower', **kwargs):
return im
def single_img_cbar_plot(fig, axis, img, show_xy_ticks=True, show_cbar=True,
x_size=1, y_size=1, num_ticks=4, cbar_label=None,
tick_font_size=14, **kwargs):
"""
Plots an image within the given axis with a color bar + label and appropriate X, Y tick labels.
This is particularly useful to get readily interpretable plots for papers
Parameters
----------
fig : matplotlib.figure object
Handle to figure
axis : matplotlib.axis object
Axis to plot this image onto
img : 2D numpy array with real values
Data for the image plot
show_xy_ticks : bool, Optional, default = True
Whether or not to show X, Y ticks
show_cbar : bool, optional, default = True
Whether or not to show the colorbar
x_size : float, optional, default = 1
Extent of tick marks in the X axis. This could be something like 1.5 for 1.5 microns
y_size : float, optional, default = 1
Extent of tick marks in y axis
num_ticks : unsigned int, optional, default = 4
Number of tick marks on the X and Y axes
cbar_label : str, optional, default = None
Labels for the colorbar. Use this for something like quantity (units)
tick_font_size : unsigned int, optional, default = 14
Font size to apply to x, y, colorbar ticks and colorbar label
kwargs : dictionary
Anything else that will be passed on to plot_map or imshow
Returns
-------
im_handle : handle to image plot
handle to image plot
cbar : handle to color bar
handle to color bar
"""
if 'clim' not in kwargs:
im_handle = plot_map(axis, img, aspect='auto', **kwargs)
else:
im_handle = axis.imshow(img, origin='lower', **kwargs)
if show_xy_ticks:
x_ticks = np.linspace(0, img.shape[1] - 1, num_ticks, dtype=int)
y_ticks = np.linspace(0, img.shape[0] - 1, num_ticks, dtype=int)
axis.set_xticks(x_ticks)
axis.set_yticks(y_ticks)
axis.set_xticklabels([str(np.round(ind * x_size / (img.shape[1] - 1), 2)) for ind in x_ticks])
axis.set_yticklabels([str(np.round(ind * y_size / (img.shape[0] - 1), 2)) for ind in y_ticks])
set_tick_font_size(axis, tick_font_size)
else:
axis.set_xticks([])
axis.set_yticks([])
if show_cbar:
cbar = fig.colorbar(im_handle, ax=axis)
if cbar_label is not None:
cbar.set_label(cbar_label, fontsize=tick_font_size)
"""
z_lims = cbar.get_clim()
cbar.set_ticks(np.linspace(z_lims[0],z_lims[1], num_ticks))
"""
cbar.ax.tick_params(labelsize=tick_font_size)
return im_handle, cbar
def plot_loops(excit_wfm, datasets, line_colors=[], dataset_names=[], evenly_spaced=True,
plots_on_side=5, x_label='', y_label='', subtitles='Position', title='',
central_resp_size=None, use_rainbow_plots=False, h5_pos=None):
......
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