Permalink
Cannot retrieve contributors at this time
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?
Plotting_Script/test.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (39 sloc)
1.78 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a test script to ensure the GUI and everythong is working | |
# change this name to plot_style_sine.py for it to pop up in the GUI and | |
# select the x and y data in the provided .dat file | |
# You should see 4 out of phase sine waves | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_sine_wave_data(x_filename, y_filename, x_limits=None, y_limits=None, x_title='X values', y_title='Y values', plot_title='Out-of-Phase Sine Waves', include_legend=True): | |
try: | |
# Load the data from the .dat files | |
x_values = np.genfromtxt(x_filename) | |
y_values = np.genfromtxt(y_filename) | |
# Check if y_values has the correct shape | |
if y_values.shape[1] != 4: | |
raise ValueError("y_values should have 4 columns for the 4 sine waves.") | |
# Create a plot | |
plt.figure(figsize=(10, 6), dpi=150) | |
# Plot each sine wave | |
plt.plot(x_values, y_values[:, 0], label='Sine Wave 1 (Phase 0)', color='blue') | |
plt.plot(x_values, y_values[:, 1], label='Sine Wave 2 (Phase 90°)', color='orange') | |
plt.plot(x_values, y_values[:, 2], label='Sine Wave 3 (Phase 180°)', color='green') | |
plt.plot(x_values, y_values[:, 3], label='Sine Wave 4 (Phase 270°)', color='red') | |
# Set the title and labels | |
plt.title(plot_title) | |
plt.xlabel(x_title) | |
plt.ylabel(y_title) | |
# Set x and y limits if provided | |
if x_limits: | |
plt.xlim(x_limits) | |
if y_limits: | |
plt.ylim(y_limits) | |
# Include legend if specified | |
if include_legend: | |
plt.legend(loc='upper right') | |
# Show grid | |
plt.grid() | |
# Display the plot | |
plt.show() | |
except Exception as e: | |
print(f"Error plotting data: {e}") | |