{"id":1130627,"date":"2025-01-08T20:41:53","date_gmt":"2025-01-08T12:41:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1130627.html"},"modified":"2025-01-08T20:41:56","modified_gmt":"2025-01-08T12:41:56","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e7%94%bb%e4%b8%89%e8%a7%92%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1130627.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u753b\u4e09\u89d2\u5f62"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100647\/acaa7e2f-e77d-453e-bcd7-631041565b22.webp\" alt=\"python\u4e2d\u5982\u4f55\u753b\u4e09\u89d2\u5f62\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u6765\u7ed8\u5236\u4e09\u89d2\u5f62\uff0c\u5982matplotlib\u3001turtle\u3001pygame\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u7ed8\u5236\u4e09\u89d2\u5f62\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u7528\u7684\u6280\u5de7\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u76842D\u7ed8\u56fe\u5e93\uff0c\u9002\u7528\u4e8e\u7ed8\u5236\u5404\u79cd\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e09\u89d2\u5f62\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1.1 \u5b89\u88c5Matplotlib<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Matplotlib\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u8be5\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u7ed8\u5236\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>matplotlib.pyplot<\/code>\u6a21\u5757\u4e2d\u7684<code>plot<\/code>\u51fd\u6570\u6765\u7ed8\u5236\u4e09\u89d2\u5f62\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u5b9a\u4e49\u4e09\u89d2\u5f62\u7684\u9876\u70b9<\/strong><\/h2>\n<p>points = [[1, 1], [4, 1], [2.5, 4]]<\/p>\n<h2><strong>\u5c06\u70b9\u8fde\u63a5\u6210\u4e09\u89d2\u5f62<\/strong><\/h2>\n<p>triangle = plt.Polygon(points, closed=True, fill=None, edgecolor=&#39;r&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u6dfb\u52a0\u4e09\u89d2\u5f62\u5230\u56fe\u5f62\u4e2d<\/strong><\/h2>\n<p>ax.add_patch(triangle)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u8f74\u7684\u8303\u56f4<\/strong><\/h2>\n<p>ax.set_xlim(0, 5)<\/p>\n<p>ax.set_ylim(0, 5)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5173\u952e\u70b9<\/strong>\uff1a\u4f7f\u7528<code>plt.Polygon<\/code>\u51fd\u6570\u521b\u5efa\u591a\u8fb9\u5f62\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u56fe\u5f62\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Turtle\u7ed8\u5236\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><p>Turtle\u662f\u4e00\u4e2a\u7528\u4e8e\u7ed8\u5236\u7b80\u5355\u56fe\u5f62\u7684Python\u5e93\uff0c\u7279\u522b\u9002\u5408\u6559\u5b66\u548c\u521d\u5b66\u8005\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Turtle\u7ed8\u5236\u4e09\u89d2\u5f62\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>2.1 \u5b89\u88c5Turtle<\/h4>\n<\/p>\n<p><p>Turtle\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2.2 \u7ed8\u5236\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<h2><strong>\u8bbe\u7f6e\u753b\u5e03\u5927\u5c0f<\/strong><\/h2>\n<p>turtle.setup(500, 500)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Turtle\u5bf9\u8c61<\/strong><\/h2>\n<p>tri = turtle.Turtle()<\/p>\n<h2><strong>\u7ed8\u5236\u4e09\u89d2\u5f62<\/strong><\/h2>\n<p>for _ in range(3):<\/p>\n<p>    tri.forward(100)  # \u5411\u524d\u79fb\u52a8100\u5355\u4f4d<\/p>\n<p>    tri.left(120)     # \u5de6\u8f6c120\u5ea6<\/p>\n<h2><strong>\u5b8c\u6210\u7ed8\u5236<\/strong><\/h2>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5173\u952e\u70b9<\/strong>\uff1a\u4f7f\u7528<code>forward<\/code>\u51fd\u6570\u5411\u524d\u79fb\u52a8\uff0c<code>left<\/code>\u51fd\u6570\u65cb\u8f6c\u89d2\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Pygame\u7ed8\u5236\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><p>Pygame\u662f\u4e00\u4e2a\u7528\u4e8e\u5f00\u53d1\u6e38\u620f\u7684Python\u5e93\uff0c\u53ef\u4ee5\u7ed8\u5236\u590d\u6742\u7684\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Pygame\u7ed8\u5236\u4e09\u89d2\u5f62\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>3.1 \u5b89\u88c5Pygame<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Pygame\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pygame<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u7ed8\u5236\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pygame<\/p>\n<p>import sys<\/p>\n<h2><strong>\u521d\u59cb\u5316Pygame<\/strong><\/h2>\n<p>pygame.init()<\/p>\n<h2><strong>\u8bbe\u7f6e\u7a97\u53e3\u5927\u5c0f<\/strong><\/h2>\n<p>screen = pygame.display.set_mode((500, 500))<\/p>\n<h2><strong>\u8bbe\u7f6e\u7a97\u53e3\u6807\u9898<\/strong><\/h2>\n<p>pygame.display.set_caption(&quot;Draw Triangle&quot;)<\/p>\n<h2><strong>\u5b9a\u4e49\u4e09\u89d2\u5f62\u7684\u9876\u70b9<\/strong><\/h2>\n<p>points = [(250, 100), (150, 400), (350, 400)]<\/p>\n<h2><strong>\u4e3b\u5faa\u73af<\/strong><\/h2>\n<p>running = True<\/p>\n<p>while running:<\/p>\n<p>    for event in pygame.event.get():<\/p>\n<p>        if event.type == pygame.QUIT:<\/p>\n<p>            running = False<\/p>\n<p>    # \u586b\u5145\u80cc\u666f\u989c\u8272<\/p>\n<p>    screen.fill((255, 255, 255))<\/p>\n<p>    # \u7ed8\u5236\u4e09\u89d2\u5f62<\/p>\n<p>    pygame.draw.polygon(screen, (0, 0, 255), points, 2)<\/p>\n<p>    # \u66f4\u65b0\u663e\u793a<\/p>\n<p>    pygame.display.flip()<\/p>\n<h2><strong>\u9000\u51faPygame<\/strong><\/h2>\n<p>pygame.quit()<\/p>\n<p>sys.exit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5173\u952e\u70b9<\/strong>\uff1a\u4f7f\u7528<code>pygame.draw.polygon<\/code>\u51fd\u6570\u7ed8\u5236\u591a\u8fb9\u5f62\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7ed8\u5236\u5e26\u989c\u8272\u586b\u5145\u7684\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u7ed8\u5236\u7684\u4e09\u89d2\u5f62\u90fd\u662f\u7a7a\u5fc3\u7684\u3002\u5982\u679c\u9700\u8981\u7ed8\u5236\u5e26\u989c\u8272\u586b\u5145\u7684\u4e09\u89d2\u5f62\uff0c\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u4fee\u6539\uff1a<\/p>\n<\/p>\n<p><h4>4.1 Matplotlib\u5e26\u989c\u8272\u586b\u5145\u7684\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>points = [[1, 1], [4, 1], [2.5, 4]]<\/p>\n<p>triangle = plt.Polygon(points, closed=True, fill=True, edgecolor=&#39;r&#39;, facecolor=&#39;blue&#39;)<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.add_patch(triangle)<\/p>\n<p>ax.set_xlim(0, 5)<\/p>\n<p>ax.set_ylim(0, 5)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 Turtle\u5e26\u989c\u8272\u586b\u5145\u7684\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<p>turtle.setup(500, 500)<\/p>\n<p>tri = turtle.Turtle()<\/p>\n<p>tri.begin_fill()  # \u5f00\u59cb\u586b\u5145<\/p>\n<p>tri.fillcolor(&quot;blue&quot;)<\/p>\n<p>for _ in range(3):<\/p>\n<p>    tri.forward(100)<\/p>\n<p>    tri.left(120)<\/p>\n<p>tri.end_fill()  # \u7ed3\u675f\u586b\u5145<\/p>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.3 Pygame\u5e26\u989c\u8272\u586b\u5145\u7684\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pygame<\/p>\n<p>import sys<\/p>\n<p>pygame.init()<\/p>\n<p>screen = pygame.display.set_mode((500, 500))<\/p>\n<p>pygame.display.set_caption(&quot;Draw Triangle&quot;)<\/p>\n<p>points = [(250, 100), (150, 400), (350, 400)]<\/p>\n<p>running = True<\/p>\n<p>while running:<\/p>\n<p>    for event in pygame.event.get():<\/p>\n<p>        if event.type == pygame.QUIT:<\/p>\n<p>            running = False<\/p>\n<p>    screen.fill((255, 255, 255))<\/p>\n<p>    pygame.draw.polygon(screen, (0, 0, 255), points)<\/p>\n<p>    pygame.display.flip()<\/p>\n<p>pygame.quit()<\/p>\n<p>sys.exit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f18\u5316\u548c\u9ad8\u7ea7\u6280\u5de7<\/h3>\n<\/p>\n<p><h4>5.1 \u52a8\u6001\u7ed8\u5236\u4e09\u89d2\u5f62<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u52a8\u6001\u5730\u7ed8\u5236\u4e09\u89d2\u5f62\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u7528\u6237\u8f93\u5165\u7684\u9876\u70b9\u5750\u6807\u6765\u7ed8\u5236\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Matplotlib\u5b9e\u73b0\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>points = []<\/p>\n<p>def onclick(event):<\/p>\n<p>    if len(points) &lt; 3:<\/p>\n<p>        points.append([event.xdata, event.ydata])<\/p>\n<p>        plt.plot(event.xdata, event.ydata, &#39;ro&#39;)<\/p>\n<p>        if len(points) == 3:<\/p>\n<p>            triangle = plt.Polygon(points, closed=True, fill=True, edgecolor=&#39;r&#39;, facecolor=&#39;blue&#39;)<\/p>\n<p>            plt.gca().add_patch(triangle)<\/p>\n<p>        plt.draw()<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.set_xlim(0, 10)<\/p>\n<p>ax.set_ylim(0, 10)<\/p>\n<p>fig.canvas.mpl_connect(&#39;button_press_event&#39;, onclick)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u52a8\u753b\u6548\u679c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Python\u7684\u52a8\u753b\u5e93\u521b\u5efa\u52a8\u6001\u7684\u4e09\u89d2\u5f62\u7ed8\u5236\u6548\u679c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Matplotlib\u7684<code>FuncAnimation<\/code>\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.animation as animation<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.set_xlim(0, 10)<\/p>\n<p>ax.set_ylim(0, 10)<\/p>\n<p>points = [[1, 1], [4, 1], [2.5, 4]]<\/p>\n<p>triangle = plt.Polygon(points, closed=True, fill=True, edgecolor=&#39;r&#39;, facecolor=&#39;blue&#39;)<\/p>\n<p>ax.add_patch(triangle)<\/p>\n<p>def update(num):<\/p>\n<p>    triangle.set_xy(points)<\/p>\n<p>    points[0][0] += 0.1<\/p>\n<p>    return triangle,<\/p>\n<p>ani = animation.FuncAnimation(fig, update, frames=100, interval=100, blit=True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5173\u952e\u70b9<\/strong>\uff1a\u4f7f\u7528<code>FuncAnimation<\/code>\u521b\u5efa\u52a8\u753b\u6548\u679c\uff0c\u5e76\u901a\u8fc7\u66f4\u65b0\u9876\u70b9\u5750\u6807\u6765\u52a8\u6001\u7ed8\u5236\u4e09\u89d2\u5f62\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u8bb2\u89e3\u4e86\u5982\u4f55\u4f7f\u7528Python\u7684Matplotlib\u3001Turtle\u548cPygame\u5e93\u6765\u7ed8\u5236\u4e09\u89d2\u5f62\uff0c\u5e76\u63d0\u4f9b\u4e86\u591a\u4e2a\u793a\u4f8b\u4ee3\u7801\u3002\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0cTurtle\u5e93\u53ef\u80fd\u662f\u6700\u7b80\u5355\u7684\u9009\u62e9\uff0c\u800cMatplotlib\u548cPygame\u5219\u9002\u7528\u4e8e\u9700\u8981\u66f4\u591a\u63a7\u5236\u548c\u529f\u80fd\u7684\u9ad8\u7ea7\u7528\u6237\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u5728Python\u4e2d\u8f7b\u677e\u7ed8\u5236\u5404\u79cd\u4e09\u89d2\u5f62\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u7ed8\u5236\u4e09\u89d2\u5f62\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0cMatplotlib\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u5404\u79cd\u5f62\u72b6\uff0c\u5305\u62ec\u4e09\u89d2\u5f62\u3002\u8981\u7ed8\u5236\u4e09\u89d2\u5f62\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Matplotlib\u5e93\u3002\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u4e09\u89d2\u5f62\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\n# \u5b9a\u4e49\u4e09\u89d2\u5f62\u7684\u4e09\u4e2a\u9876\u70b9\nx = [0, 1, 2]\ny = [0, 2, 0]\n\n# \u4f7f\u7528plot\u7ed8\u5236\u4e09\u89d2\u5f62\nplt.fill(x, y, &#39;b&#39;)  # &#39;b&#39;\u8868\u793a\u586b\u5145\u989c\u8272\u4e3a\u84dd\u8272\nplt.xlim(-1, 3)\nplt.ylim(-1, 3)\nplt.grid()\nplt.show()\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u7ed8\u5236\u4e09\u89d2\u5f62\u65f6\uff0c\u5982\u4f55\u81ea\u5b9a\u4e49\u989c\u8272\u548c\u6837\u5f0f\uff1f<\/strong><br \/>\u5728\u7ed8\u5236\u4e09\u89d2\u5f62\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>fill<\/code>\u51fd\u6570\u7684\u53c2\u6570\u6765\u8bbe\u7f6e\u989c\u8272\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u586b\u5145\u989c\u8272\u6539\u4e3a\u7ea2\u8272\u5e76\u8bbe\u7f6e\u8fb9\u6846\u6837\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">plt.fill(x, y, color=&#39;red&#39;, edgecolor=&#39;black&#39;, linewidth=2)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u4e09\u89d2\u5f62\u586b\u5145\u4e3a\u7ea2\u8272\uff0c\u8fb9\u6846\u4e3a\u9ed1\u8272\uff0c\u4e14\u8fb9\u6846\u5bbd\u5ea6\u4e3a2\u4e2a\u50cf\u7d20\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u7ed8\u5236\u591a\u8fb9\u5f62\u800c\u4e0d\u4ec5\u4ec5\u662f\u4e09\u89d2\u5f62\uff1f<\/strong><br \/>\u8981\u7ed8\u5236\u591a\u8fb9\u5f62\uff0c\u60a8\u53ea\u9700\u5b9a\u4e49\u66f4\u591a\u7684\u9876\u70b9\u5750\u6807\uff0c\u5e76\u4f7f\u7528\u76f8\u540c\u7684<code>fill<\/code>\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u7ed8\u5236\u4e00\u4e2a\u4e94\u8fb9\u5f62\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4e24\u4e2a\u9876\u70b9\uff1a<\/p>\n<pre><code class=\"language-python\">x = [0, 1, 2, 1.5, 0.5]\ny = [0, 2, 0, -1, -1]\nplt.fill(x, y, &#39;green&#39;)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4efb\u610f\u5f62\u72b6\u7684\u591a\u8fb9\u5f62\uff0c\u53ea\u9700\u786e\u4fdd\u5750\u6807\u7684\u987a\u5e8f\u662f\u6b63\u786e\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u6765\u7ed8\u5236\u4e09\u89d2\u5f62\uff0c\u5982matplotlib\u3001turtle\u3001pygame\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb [&hellip;]","protected":false},"author":3,"featured_media":1130640,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1130627"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1130627"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1130627\/revisions"}],"predecessor-version":[{"id":1130645,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1130627\/revisions\/1130645"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1130640"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1130627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1130627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1130627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}