首页 > 解决方案 > matplotlib 没有绘制整条曲线

问题描述

在此处输入图像描述我正在绘制几条曲线,但不知何故并没有继续整个情节。我绘制到https://www.desmos.com/calculator?lang=es

[![import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
np.seterr(divide='ignore', invalid='ignore')
# Construct lines
# x > 0
x = np.linspace(1, 20, 2000)
# C1
y1 = np.sqrt(560000/(np.pi*x))
#C2
y2= 10*x/4
#C3
plt.axvline(x=35, color='r')

# Add lines to complete first 2 constraints
# plt.axvline(y=35, color='r')

# Make plot
plt.plot(x, y1, label=r'$\frac{\pi}{4} {x_{1}} {x_{2}}^2 \leq 140000$')
plt.plot(x, y2, label=r'$10 x_{1} - 4 x_{2}\leq 0$')

# plt.xlim((0, 40))
# plt.ylim((0, 1000))
plt.xlabel(r'$x_1$')
plt.ylabel(r'$x_2$')
#plot legend
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)][1]][1]

标签: pythonmatplotlibjupyter-notebook

解决方案


我刚刚发现错误,x = np.linspace(1, 20, 2000)需要调整最大限制x = np.linspace(1, 100, 2000)


推荐阅读