我正在尝试绘制具有 3 个平面的线性系统的解,解是点 (1,1,1) 我已经使用 point 命令绘制了该点,但我怀疑该点不在正确的位置:
\n\nax.plot([1.], [1.], [1.], markerfacecolor=\'k\', markeredgecolor=\'k\', marker=\'o\', markersize=5, alpha=0.6)\nRun Code Online (Sandbox Code Playgroud)\n\n谢谢\n好的,代码是:
\n\n#/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom sympy.solvers import *\nfrom sympy import *\nfrom matplotlib import rcParams\n\n\n# Activating LateX\nrcParams[\'text.latex.unicode\'] = True\nrcParams[\'text.usetex\'] = True\nrcParams[\'text.latex.preamble\'] = \'\\\\usepackage{amsthm}\', \'\\\\usepackage{amsmath}\', \'\\\\usepackage{amssymb}\',\n\'\\\\usepackage{amsfonts}\', \'\\\\usepackage[T1]{fontenc}\', \'\\\\usepackage[utf8]{inputenc}\'\n\n\n# Declaring the three planes as functions\nf1 = lambda x, y: x + y -1\nf2 = lambda x, y: 1 - x + y\nf3 = lambda x, y: 1 + x - y\n\n# Declaring symbolic variables\nx = Symbol(\'x\')\ny = Symbol(\'y\')\nz = Symbol(\'z\')\n\n# Solving the linear system\nfun1 = x+y-z-1\nfun2 = x-y+z-1\nfun3 = -x+y+z-1\nsolucion = solve([fun1, fun2, fun3], [x, y, z])\n\n# Printing the solution\npprint((\'Soluci\xc3\xb3n Del Sistema es: {}\').format(solucion))\n\n\n# Stablishing our ranges for our variables\nx1 = y1 = np.arange(-5, 5, 0.25)\nceros = np.zeros(len(x1))\n\n# Stablishing our meshgrid\nx, y = np.meshgrid(x1, y1)\n\n# Our 3D Canvas Figure Plot\nfig = plt.figure()\nax = fig.add_subplot(111, projection=\'3d\')\n\n# Plotting the 3 planes\nax.plot_surface(x, y, f1(x, y), rstride=1, cstride=1, linewidth=0, antialiased=True, color=\'blue\')\nax.plot_surface(x, y, f2(x, y), rstride=1, cstride=1, linewidth=0, antialiased=True, color=\'red\')\nax.plot_surface(x, y, f3(x, y), rstride=1, cstride=1, linewidth=0, antialiased=True, color=\'green\')\nax.plot([1.], [1.], [1.], markerfacecolor=\'k\', markeredgecolor=\'k\', marker=\'o\', markersize=5, alpha=0.6)\n\n# Putting the limits in the axes\nax.set_xlim(-10, 10)\nax.set_ylim(-10, 10)\nax.set_zlim(-10, 10)\n\n# Writing the axis labels\nax.set_xlabel(\'x\', color=\'blue\')\nax.set_ylabel(\'y\', color=\'blue\')\nax.set_zlabel(\'z\', color=\'blue\')\n\n# Writing The Title of The Plot\nax.set_title(r\'$Graphical\\; Resolution\\; Linear\\; System\\; 3 \\times 3$\', fontsize=18)\n\n# Stablishing the plots of our legend labels\nblue_proxy = plt.Rectangle((0, 0), 1, 1, fc=\'b\')\nred_proxy = plt.Rectangle((0, 0), 1, 1, fc=\'r\')\ngreen_proxy = plt.Rectangle((0, 0), 1, 1, fc=\'g\')\nblack_proxy = plt.Line2D([0], [0], linestyle="none", marker=\'o\', alpha=0.6, markersize=10, markerfacecolor=\'black\')\n\n# Drawing Our Legend\nax.legend([blue_proxy,red_proxy, green_proxy, black_proxy], [r\'$x+y-z=1$\',r\'$x-y+z=1$\', r\'$-x+y+z=1$\', r\'$Sol.\\; (1,1,1)$\'], numpoints=1, loc=\'upper left\')\n\nplt.show()\nRun Code Online (Sandbox Code Playgroud)\n\n一个图像:
\n\n点 (1,1,1) 的 z 坐标不在高度 1 处,而是低于 0。因此,该点未绘制在正确的位置。\n
我认为你的代码是完全正确的。该点位于其位置(1,1,1)。您可以拖动绘图从另一个角度查看该点,您会发现该点位于正确的位置。
相信自己!通过将 point 的 z 坐标替换为 10.0,您会发现您的代码是正确的。
| 归档时间: |
|
| 查看次数: |
13131 次 |
| 最近记录: |