Last active
January 16, 2024 18:05
-
-
Save evdokimovm/c5f7318c044778a1be8f1a9b47f8186c to your computer and use it in GitHub Desktop.
visualize three phases of electrical system
This file contains hidden or 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
import matplotlib.pyplot as plt | |
import numpy as np | |
import mplcursors | |
x = np.linspace(0, 500, 1000) | |
plt.figure(figsize=(10, 6)) | |
plt.axhline(y=0, color='k', linestyle='-') | |
line1, = plt.plot(x, 220 * np.sin(x * np.pi / 180), label='220 * sin(x * π / 180)') | |
line2, = plt.plot(x, 220 * np.sin((x - 120) * np.pi / 180), label='220 * sin((x - 120) * π / 180)') | |
line3, = plt.plot(x, 220 * np.sin((x - 240) * np.pi / 180), label='220 * sin((x - 240) * π / 180)') | |
plt.title('Three phases') | |
plt.xlabel('x') | |
plt.ylabel('y') | |
plt.legend() | |
cursor = mplcursors.cursor(pickables=[line1, line2, line3], hover=True) | |
@cursor.connect("add") | |
def on_add(sel): | |
x, y = sel.target | |
s1 = np.sin(x * np.pi / 180) | |
s2 = np.sin((x - 120) * np.pi / 180) | |
s3 = np.sin((x - 240) * np.pi / 180) | |
if sel.artist == line1: | |
label = '220 * sin(x * π / 180)' | |
y = 220 * np.sin(x * np.pi / 180) | |
s = np.sin(x * np.pi / 180) | |
o = f'220 * (s1 - s3) = {220 * (s1 - s3)}' | |
elif sel.artist == line2: | |
label = '220 * sin((x - 120) * π / 180)' | |
y = 220 * np.sin((x - 120) * np.pi / 180) | |
s = np.sin((x - 120) * np.pi / 180) | |
o = f'220 * (s2 - s1) = {220 * (s2 - s1)}' | |
elif sel.artist == line3: | |
label = '220 * sin((x - 240) * π / 180)' | |
y = 220 * np.sin((x - 240) * np.pi / 180) | |
s = np.sin((x - 240) * np.pi / 180) | |
o = f'220 * (s3 - s2) = {220 * (s3 - s2)}' | |
sel.annotation.set_text(f"{label}\nx={x}\ny={y}\ns={s}\no={o}\nx (radians)={np.deg2rad(x)}") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment