Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import plot_settings as ps
# Prepare labels for each dataset based on the filenames or custom labels for the legend
label_list = ['QTBM4', 'QTBM5', 'RGF']
#########################################################################
# Set global font size
plt.rcParams.update({'font.size': 22})
font_size = 22
def plot(plot_type, dat_files, x_limits, y_limits=None, x_title='', y_title='', plot_title='', include_legend=True, show_x_ticks=True):
# Set default values if no arguments are provided
if dat_files is None:
print("Error loading File")
raise ValueError(f"Error loading dat files")
if x_limits is None:
x_limits = (0.0, 0.6)
if y_limits is None:
y_limits = ((-13.5, -4.5), (-0.5, 8.5))
if not x_title:
x_title = 'Gate Voltage (V)'
if not y_title:
y_title = 'Current'
if not plot_title:
plot_title = 'IV Comparison'
fig, ax1 = plt.subplots(figsize=(10, 6))
# Configure axes labels
ax1.set_xlabel(f"{x_title}", fontsize=font_size, labelpad=10)
ax1.set_ylabel(f"{y_title} (log10 A)", fontsize=font_size, labelpad=10)
# Style settings
color_list = ['r', 'orange', 'b']
ls_list = ['-', '--', ':']
m_list = ['o', 'o', 'x']
ms_list = [8, 15, 15]
mw_list = [2, 2, 2]
# Plot data on the first y-axis (log scale)
for filepath, label_name, l_style, m_style, m_size, m_width, color in zip(
dat_files, label_list, ls_list, m_list, ms_list, mw_list, color_list):
x_data, y_data = ps.load_IV_Data_Log_lin(filepath)
y_data_log = np.log10(np.array(y_data))
ax1.plot(
x_data, y_data_log,
marker=m_style, ms=m_size, markerfacecolor='none', markeredgewidth=m_width,
ls=l_style, color=color, label=None
)
# Set y-axis limits for ax1 (log scale)
ax1.set_ylim(y_limits[0] if y_limits else (None, None))
ax1.set_xlim(x_limits)
ax1.yaxis.set_major_locator(MultipleLocator(1))
# Create a second y-axis (right) sharing the same x-axis
ax2 = ax1.twinx()
ax2.set_ylabel(f"{y_title} (μA)", fontsize=font_size, labelpad=15)
# Plot the same data on the second y-axis (linear scale)
for filepath, label_name, l_style, m_style, m_size, m_width, color in zip(
dat_files, label_list, ls_list, m_list, ms_list, mw_list, color_list):
x_data, y_data = ps.load_IV_Data_Log_lin(filepath)
y_data_linear = np.array(y_data) * 1e6
ax2.plot(
x_data, y_data_linear,
marker=m_style, ms=m_size, markerfacecolor='none', markeredgewidth=m_width,
ls=l_style, color=color, label=f"{label_name}" if include_legend else None
)
# Set y-axis limits for ax2 (linear scale)
ax2.set_ylim(y_limits[1] if y_limits else (None, None))
ax2.yaxis.set_major_locator(MultipleLocator(2))
# Add legends if required
if include_legend:
ax2.legend(loc='upper left', fontsize=22, frameon=False)
# Set x-axis ticks visibility
if not show_x_ticks:
ax1.xaxis.set_visible(False)
# Adjust layout and set plot title
plt.tight_layout()
if plot_title:
plt.title(plot_title, fontsize=font_size)
# Display the plot
plt.show()
# Example usage
"""
dat_files = ['/Users/austintoro/Downloads/Plotting_Script-Experimental/IV_compare/ramper_IV_QTBM4.dat',
'/Users/austintoro/Downloads/Plotting_Script-Experimental/IV_compare/ramper_IV_QTBM5.dat',
'/Users/austintoro/Downloads/Plotting_Script-Experimental/IV_compare/ramper_IV_RGF_converged.dat']
x_limits = (0.0, 0.6)
y_limits = ((-13.5, -4.5), (-0.5, 8.5))
plot(
plot_type='dual_y_axes',
dat_files=dat_files,
x_limits=x_limits,
y_limits=y_limits,
x_title='Gate Voltage (V)',
y_title='Current',
plot_title='IV Comparison',
include_legend=True
)
"""