Created
August 21, 2023 02:20
-
-
Save cassc/472182d48aa0f91b974b14f91e4db4af to your computer and use it in GitHub Desktop.
Python plot x*y=k
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# Define the function y = k/x | |
def f(x, k=100): | |
return k / x | |
# Generate x values | |
x = np.linspace(0.1, 10, 400) # Start from 0.1 to avoid division by zero | |
y = f(x) | |
# Plotting | |
plt.figure(figsize=(8, 6)) | |
plt.plot(x, y, label='y = 100/x') | |
plt.plot(x, -y, label='y = -100/x') # Negative part of the hyperbola | |
plt.title('Plot of x*y = 100') | |
plt.xlabel('x') | |
plt.ylabel('y') | |
plt.grid(True) | |
plt.axhline(0, color='black',linewidth=0.5) | |
plt.axvline(0, color='black',linewidth=0.5) | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment