Untitled

mail@pastecode.io avatar
unknown
python
17 days ago
1.5 kB
4
Indexable
Never
import numpy as np
import matplotlib.pyplot as plt

# Create an array of 500 evenly spaced points between 0 and 30 for the x-axis (x1)
x1 = np.linspace(0, 30, 500)

# Define the equation of the line for the "tissues" constraint: 0.3 * x1 + 0.1 * x2 <= 2.7
# Rearranged as: x2 = (2.7 - 0.3 * x1) / 0.1
x2_tissues = (2.7 - 0.3 * x1) / 0.1

# Define the equation of the line for the "tumor" constraint: 0.6 * x1 + 0.4 * x2 >= 6
# Rearranged as: x2 = (6 - 0.6 * x1) / 0.4
x2_tumor = (6 - 0.6 * x1) / 0.4

# Plot the line for the tissue constraint
plt.plot(x1, x2_tissues, label=r'0.3 * x1 + 0.1 * x2 <= 2.7', color='blue')

# Plot the line for the tumor constraint
plt.plot(x1, x2_tumor, label=r'0.6 * x1 + 0.4 * x2 >= 6', color='red')

# Set the x-axis limits to only show values between 0 and 15 for better visualization
plt.xlim(0, 15)

# Fill the area below the tissue constraint line with brown color to indicate feasible region
plt.fill_between(x1, x2_tissues, color='tab:brown', label='Feasible Region')

# Fill the area above the tumor constraint line with brown color
plt.fill_between(x1, x2_tumor, color='tab:brown')

# Remove the overlapping area between the two regions to highlight the true feasible region
plt.fill_between(x1, x2_tissues, x2_tumor, color='white')

# Set the y-axis limits between 0 and 30
plt.ylim(0, 30)

# Add a legend to describe the lines and regions in the plot
plt.legend()

# Label the x-axis as "Beam 1"
plt.xlabel("Beam 1")

# Label the y-axis as "Beam 2"
plt.ylabel("Beam 2")

# Show the plot
plt.show()
Leave a Comment