{"id":1114557,"date":"2025-01-08T17:58:32","date_gmt":"2025-01-08T09:58:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1114557.html"},"modified":"2025-01-08T17:58:36","modified_gmt":"2025-01-08T09:58:36","slug":"python%e5%a6%82%e4%bd%95%e7%94%bb%e4%b8%80%e4%b8%aa%e5%bd%a9%e8%89%b2%e7%9a%84%e5%9c%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1114557.html","title":{"rendered":"python\u5982\u4f55\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075659\/a27da63e-02b9-4125-a77d-e7a8d22261be.webp\" alt=\"python\u5982\u4f55\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706\" \/><\/p>\n<p><p> <strong>Python\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706\u7684\u6838\u5fc3\u89c2\u70b9\u6709\uff1a\u4f7f\u7528matplotlib\u5e93\u3001\u4f7f\u7528PIL\u5e93\u3001\u4f7f\u7528turtle\u5e93\u3001\u9009\u62e9\u989c\u8272\u548c\u586b\u5145\u65b9\u5f0f\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528matplotlib\u5e93\u662f\u6700\u5e38\u7528\u548c\u76f4\u89c2\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\u548c\u7b80\u5355\u7684\u63a5\u53e3\uff0c\u53ef\u4ee5\u8f7b\u677e\u753b\u51fa\u5f69\u8272\u7684\u5706\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528MATPLOTLIB\u5e93\u753b\u5f69\u8272\u5706<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u5404\u79cd\u56fe\u5f62\u548c\u56fe\u8868\u3002\u4f7f\u7528Matplotlib\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u51e0\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706<\/strong><\/h2>\n<p>circle = plt.Circle((0.5, 0.5), 0.4, color=&#39;blue&#39;, fill=True)<\/p>\n<p>ax.add_artist(circle)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5750\u6807\u7cfb\u7684\u8303\u56f4<\/strong><\/h2>\n<p>ax.set_xlim(0, 1)<\/p>\n<p>ax.set_ylim(0, 1)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165matplotlib.pyplot\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u56fe\u5f62\u548c\u5750\u6807\u8f74\u5bf9\u8c61\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528plt.Circle\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5706\uff0c\u5e76\u8bbe\u7f6e\u5176\u989c\u8272\u548c\u586b\u5145\u5c5e\u6027\u3002\u6700\u540e\uff0c\u6211\u4eec\u5c06\u5706\u6dfb\u52a0\u5230\u5750\u6807\u8f74\u4e2d\uff0c\u5e76\u663e\u793a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u63cf\u8ff0\uff1a\u9009\u62e9\u989c\u8272\u548c\u586b\u5145\u65b9\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7ed8\u5236\u5f69\u8272\u5706\u65f6\uff0c\u9009\u62e9\u989c\u8272\u548c\u586b\u5145\u65b9\u5f0f\u662f\u5173\u952e\u6b65\u9aa4\u3002Matplotlib\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u6307\u5b9a\u989c\u8272\uff0c\u53ef\u4ee5\u4f7f\u7528\u989c\u8272\u540d\u79f0\u3001RGB\u503c\u3001\u5341\u516d\u8fdb\u5236\u989c\u8272\u4ee3\u7801\u7b49\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6efill\u53c2\u6570\u6765\u63a7\u5236\u5706\u662f\u5426\u586b\u5145\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u4e0d\u540c\u7684\u989c\u8272\u548c\u586b\u5145\u65b9\u5f0f\u7ed8\u5236\u591a\u4e2a\u5706\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u4f7f\u7528\u989c\u8272\u540d\u79f0<\/strong><\/h2>\n<p>circle1 = plt.Circle((0.2, 0.5), 0.1, color=&#39;red&#39;, fill=True)<\/p>\n<p>ax.add_artist(circle1)<\/p>\n<h2><strong>\u4f7f\u7528RGB\u503c<\/strong><\/h2>\n<p>circle2 = plt.Circle((0.5, 0.5), 0.1, color=(0, 1, 0), fill=True)<\/p>\n<p>ax.add_artist(circle2)<\/p>\n<h2><strong>\u4f7f\u7528\u5341\u516d\u8fdb\u5236\u989c\u8272\u4ee3\u7801<\/strong><\/h2>\n<p>circle3 = plt.Circle((0.8, 0.5), 0.1, color=&#39;#0000FF&#39;, fill=True)<\/p>\n<p>ax.add_artist(circle3)<\/p>\n<p>ax.set_xlim(0, 1)<\/p>\n<p>ax.set_ylim(0, 1)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u989c\u8272\u540d\u79f0\uff08&#39;red&#39;\uff09\u3001RGB\u503c\uff08(0, 1, 0)\uff09\u548c\u5341\u516d\u8fdb\u5236\u989c\u8272\u4ee3\u7801\uff08&#39;#0000FF&#39;\uff09\u6765\u5206\u522b\u8bbe\u7f6e\u4e09\u4e2a\u5706\u7684\u989c\u8272\u3002\u6b64\u5916\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6efill\u53c2\u6570\u4e3aFalse\u6765\u7ed8\u5236\u4e0d\u586b\u5145\u7684\u5706\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528PIL\u5e93\u753b\u5f69\u8272\u5706<\/p>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662fPython\u4e2d\u5904\u7406\u56fe\u50cf\u7684\u6807\u51c6\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4f7f\u7528PIL\u5e93\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u5f69\u8272\u5706\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&#39;RGB&#39;, (200, 200), &#39;white&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706<\/strong><\/h2>\n<p>draw.ellipse((50, 50, 150, 150), fill=&#39;blue&#39;, outline=&#39;black&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165PIL\u5e93\u4e2d\u7684Image\u548cImageDraw\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf\u548c\u7ed8\u56fe\u5bf9\u8c61\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528draw.ellipse\u51fd\u6570\u7ed8\u5236\u4e00\u4e2a\u5f69\u8272\u7684\u5706\uff0c\u5e76\u8bbe\u7f6e\u5176\u586b\u5145\u989c\u8272\u548c\u8fb9\u6846\u989c\u8272\u3002\u6700\u540e\uff0c\u6211\u4eec\u663e\u793a\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528TURTLE\u5e93\u753b\u5f69\u8272\u5706<\/p>\n<\/p>\n<p><p>Turtle\u662fPython\u4e2d\u4e00\u4e2a\u7b80\u5355\u7684\u7ed8\u56fe\u5e93\uff0c\u7279\u522b\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\u3002\u4f7f\u7528Turtle\u5e93\u53ef\u4ee5\u8f7b\u677e\u7ed8\u5236\u5f69\u8272\u5706\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u753b\u5e03<\/strong><\/h2>\n<p>screen = turtle.Screen()<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u753b\u7b14<\/strong><\/h2>\n<p>pen = turtle.Turtle()<\/p>\n<h2><strong>\u8bbe\u7f6e\u753b\u7b14\u989c\u8272<\/strong><\/h2>\n<p>pen.color(&#39;blue&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u586b\u5145\u989c\u8272<\/strong><\/h2>\n<p>pen.fillcolor(&#39;blue&#39;)<\/p>\n<h2><strong>\u5f00\u59cb\u586b\u5145<\/strong><\/h2>\n<p>pen.begin_fill()<\/p>\n<h2><strong>\u753b\u4e00\u4e2a\u5706<\/strong><\/h2>\n<p>pen.circle(100)<\/p>\n<h2><strong>\u7ed3\u675f\u586b\u5145<\/strong><\/h2>\n<p>pen.end_fill()<\/p>\n<h2><strong>\u9690\u85cf\u753b\u7b14<\/strong><\/h2>\n<p>pen.hideturtle()<\/p>\n<h2><strong>\u4fdd\u6301\u7a97\u53e3\u6253\u5f00<\/strong><\/h2>\n<p>turtle.done()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165turtle\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u753b\u5e03\u548c\u753b\u7b14\u5bf9\u8c61\u3002\u63a5\u7740\uff0c\u6211\u4eec\u8bbe\u7f6e\u753b\u7b14\u7684\u989c\u8272\u548c\u586b\u5145\u989c\u8272\uff0c\u5e76\u4f7f\u7528pen.begin_fill\u548cpen.end_fill\u51fd\u6570\u6765\u63a7\u5236\u586b\u5145\u8fc7\u7a0b\u3002\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528pen.circle\u51fd\u6570\u7ed8\u5236\u4e00\u4e2a\u5706\uff0c\u5e76\u4fdd\u6301\u7a97\u53e3\u6253\u5f00\u4ee5\u663e\u793a\u7ed8\u56fe\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u9009\u62e9\u7ed8\u56fe\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u6839\u636e\u4e0d\u540c\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u7684\u7ed8\u56fe\u5de5\u5177\u6765\u7ed8\u5236\u5f69\u8272\u5706\u3002Matplotlib\u9002\u7528\u4e8e\u7ed8\u5236\u590d\u6742\u56fe\u5f62\u548c\u56fe\u8868\uff0cPIL\u9002\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff0cTurtle\u9002\u7528\u4e8e\u6559\u5b66\u548c\u7b80\u5355\u7ed8\u56fe\u3002\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u53ef\u4ee5\u63d0\u9ad8\u7ed8\u56fe\u6548\u7387\u548c\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5982\u679c\u9700\u8981\u5728\u56fe\u8868\u4e2d\u7ed8\u5236\u5f69\u8272\u5706\uff0c\u53ef\u4ee5\u9009\u62e9Matplotlib\uff1b\u5982\u679c\u9700\u8981\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u5f69\u8272\u5706\uff0c\u53ef\u4ee5\u9009\u62e9PIL\uff1b\u5982\u679c\u9700\u8981\u6559\u5b66\u6f14\u793a\uff0c\u53ef\u4ee5\u9009\u62e9Turtle\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528MATPLOTLIB\u8fdb\u884c\u590d\u6742\u56fe\u5f62\u7ed8\u5236<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u7ed8\u5236\u7b80\u5355\u7684\u5f69\u8272\u5706\uff0cMatplotlib\u8fd8\u53ef\u4ee5\u7ed8\u5236\u590d\u6742\u7684\u56fe\u5f62\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u7ed8\u5236\u591a\u4e2a\u5f69\u8272\u5706\u3001\u5e26\u6709\u6e10\u53d8\u8272\u7684\u5706\u3001\u5e26\u6709\u9634\u5f71\u7684\u5706\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6e10\u53d8\u8272\u7684\u5706<\/strong><\/h2>\n<p>gradient = np.linspace(0, 1, 100)<\/p>\n<p>circle = plt.Circle((0.5, 0.5), 0.4, color=(1, gradient[50], 0), fill=True)<\/p>\n<p>ax.add_artist(circle)<\/p>\n<h2><strong>\u6dfb\u52a0\u9634\u5f71\u6548\u679c<\/strong><\/h2>\n<p>circle_shadow = plt.Circle((0.55, 0.55), 0.4, color=&#39;gray&#39;, alpha=0.5, fill=True)<\/p>\n<p>ax.add_artist(circle_shadow)<\/p>\n<p>ax.set_xlim(0, 1)<\/p>\n<p>ax.set_ylim(0, 1)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528numpy\u5e93\u521b\u5efa\u4e86\u4e00\u4e2a\u6e10\u53d8\u8272\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528\u5b83\u6765\u8bbe\u7f6e\u5706\u7684\u989c\u8272\u3002\u7136\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2a\u7a0d\u504f\u79fb\u4f4d\u7f6e\u7684\u7070\u8272\u5706\u6765\u521b\u5efa\u9634\u5f71\u6548\u679c\u3002\u8fd9\u6837\u53ef\u4ee5\u7ed8\u5236\u51fa\u66f4\u590d\u6742\u548c\u7f8e\u89c2\u7684\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5e94\u7528\u5b9e\u4f8b\uff1a\u7ed8\u5236\u5f69\u8272\u5706\u5f62\u56fe\u6807<\/p>\n<\/p>\n<p><p>\u7ed8\u5236\u5f69\u8272\u5706\u53ef\u4ee5\u5e94\u7528\u4e8e\u8bb8\u591a\u5b9e\u9645\u573a\u666f\uff0c\u4f8b\u5982\u7ed8\u5236\u5f69\u8272\u5706\u5f62\u56fe\u6807\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528PIL\u5e93\u7ed8\u5236\u5f69\u8272\u5706\u5f62\u56fe\u6807\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&#39;RGB&#39;, (200, 200), &#39;white&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706<\/strong><\/h2>\n<p>draw.ellipse((50, 50, 150, 150), fill=&#39;blue&#39;, outline=&#39;black&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u672c<\/strong><\/h2>\n<p>font = ImageFont.truetype(&quot;arial.ttf&quot;, 40)<\/p>\n<p>draw.text((75, 80), &quot;A&quot;, font=font, fill=&#39;white&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&#39;icon.png&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf\u548c\u7ed8\u56fe\u5bf9\u8c61\uff0c\u7136\u540e\u7ed8\u5236\u4e00\u4e2a\u5f69\u8272\u7684\u5706\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528draw.text\u51fd\u6570\u6dfb\u52a0\u6587\u672c\uff0c\u5e76\u8bbe\u7f6e\u5b57\u4f53\u548c\u989c\u8272\u3002\u6700\u540e\uff0c\u6211\u4eec\u4fdd\u5b58\u548c\u663e\u793a\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ed8\u5236\u5f69\u8272\u7684\u5706\uff0c\u5305\u62ec\u4f7f\u7528Matplotlib\u3001PIL\u548cTurtle\u5e93\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u3002\u7ed8\u5236\u5f69\u8272\u5706\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u9009\u62e9\u5408\u9002\u7684\u989c\u8272\u548c\u586b\u5145\u65b9\u5f0f\uff0c\u4ee5\u63d0\u9ad8\u56fe\u5f62\u7684\u7f8e\u89c2\u5ea6\u548c\u53ef\u8bfb\u6027\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u7ed8\u5236\u590d\u6742\u7684\u56fe\u5f62\u548c\u5e94\u7528\u5b9e\u4f8b\uff0c\u5982\u7ed8\u5236\u6e10\u53d8\u8272\u5706\u548c\u5f69\u8272\u5706\u5f62\u56fe\u6807\uff0c\u4ee5\u63d0\u9ad8\u7ed8\u56fe\u6280\u80fd\u548c\u5e94\u7528\u80fd\u529b\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\u5f69\u8272\u5706\uff1f<\/strong><br \/>\u4f7f\u7528Matplotlib\u5e93\u662f\u7ed8\u5236\u5f69\u8272\u5706\u7684\u5e38\u7528\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u5b89\u88c5Matplotlib\u3002\u63a5\u7740\uff0c\u53ef\u4ee5\u5229\u7528<code>plt.Circle()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u5706\u5f62\uff0c\u5e76\u901a\u8fc7\u8bbe\u7f6e<code>color<\/code>\u53c2\u6570\u6765\u5b9a\u4e49\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nfig, ax = plt.subplots()\ncircle = plt.Circle((0.5, 0.5), 0.4, color=&#39;blue&#39;)  # \u5706\u5fc3\u4f4d\u7f6e\u548c\u534a\u5f84\nax.add_artist(circle)\nax.set_xlim(0, 1)\nax.set_ylim(0, 1)\nax.set_aspect(&#39;equal&#39;, &#39;box&#39;)\nplt.show()\n<\/code><\/pre>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u5728Python\u4e2d\u7ed8\u5236\u6e10\u53d8\u8272\u7684\u5706\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib<\/code>\u7ed3\u5408<code>numpy<\/code>\u548c<code>PIL<\/code>\u5e93\u6765\u5b9e\u73b0\u6e10\u53d8\u8272\u7684\u6548\u679c\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u6e10\u53d8\u8272\u7684\u56fe\u50cf\uff0c\u7136\u540e\u5c06\u5176\u5e94\u7528\u5230\u5706\u5f62\u4e0a\uff0c\u53ef\u4ee5\u8fbe\u5230\u6240\u9700\u6548\u679c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9700\u8981\u5bf9\u50cf\u7d20\u8fdb\u884c\u5904\u7406\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528<code>imshow()<\/code>\u51fd\u6570\u6765\u663e\u793a\u6e10\u53d8\u6548\u679c\u3002<\/p>\n<p><strong>\u9664\u4e86Matplotlib\uff0c\u8fd8\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u7ed8\u5236\u5f69\u8272\u5706\uff1f<\/strong><br \/>\u9664\u4e86Matplotlib\uff0cPython\u4e2d\u8fd8\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u7ed8\u5236\u5f69\u8272\u5706\uff0c\u4f8b\u5982<code>Pygame<\/code>\u548c<code>Turtle<\/code>\u3002<code>Pygame<\/code>\u66f4\u9002\u5408\u7528\u4e8e\u6e38\u620f\u5f00\u53d1\uff0c\u800c<code>Turtle<\/code>\u5219\u662f\u4e00\u4e2a\u9002\u5408\u521d\u5b66\u8005\u7684\u7ed8\u56fe\u5de5\u5177\uff0c\u7b80\u5355\u6613\u7528\u3002\u9009\u62e9\u5408\u9002\u7684\u5e93\u53d6\u51b3\u4e8e\u4f60\u7684\u5177\u4f53\u9700\u6c42\u548c\u9879\u76ee\u7c7b\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u753b\u4e00\u4e2a\u5f69\u8272\u7684\u5706\u7684\u6838\u5fc3\u89c2\u70b9\u6709\uff1a\u4f7f\u7528matplotlib\u5e93\u3001\u4f7f\u7528PIL\u5e93\u3001\u4f7f\u7528turtle\u5e93\u3001\u9009\u62e9\u989c\u8272 [&hellip;]","protected":false},"author":3,"featured_media":1114560,"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\/1114557"}],"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=1114557"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114557\/revisions"}],"predecessor-version":[{"id":1114561,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1114557\/revisions\/1114561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1114560"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1114557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1114557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1114557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}