{"id":1156701,"date":"2025-01-13T18:19:26","date_gmt":"2025-01-13T10:19:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1156701.html"},"modified":"2025-01-13T18:19:28","modified_gmt":"2025-01-13T10:19:28","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e7%bb%98%e5%88%b6%e5%8d%8a%e5%9c%86","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1156701.html","title":{"rendered":"\u5982\u4f55\u7528python\u7ed8\u5236\u534a\u5706"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25195106\/4f1cc403-5823-49b7-aed5-a4545f990fed.webp\" alt=\"\u5982\u4f55\u7528python\u7ed8\u5236\u534a\u5706\" \/><\/p>\n<p><p> \u4f7f\u7528Python\u7ed8\u5236\u534a\u5706\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528matplotlib\u5e93\u3001\u4f7f\u7528turtle\u5e93\u3001\u4ee5\u53ca\u4f7f\u7528pygame\u5e93<strong>\u3002\u5176\u4e2d\u6700\u5e38\u7528\u548c\u65b9\u4fbf\u7684\u65b9\u6cd5\u662f\u4f7f\u7528matplotlib\u5e93<\/strong>\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u80fd\u591f\u8f7b\u677e\u5b9e\u73b0\u5305\u62ec\u534a\u5706\u5728\u5185\u7684\u5404\u79cd\u56fe\u5f62\u7ed8\u5236\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528matplotlib\u5e93\u7ed8\u5236\u534a\u5706\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5matplotlib\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528matplotlib\u7ed8\u5236\u534a\u5706<\/h3>\n<\/p>\n<p><h4>1. \u7ed8\u5236\u57fa\u672c\u534a\u5706<\/h4>\n<\/p>\n<p><p>\u8981\u7ed8\u5236\u4e00\u4e2a\u57fa\u672c\u7684\u534a\u5706\uff0c\u53ef\u4ee5\u4f7f\u7528matplotlib\u7684<code>Arc<\/code>\u7c7b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>from matplotlib.patches import Arc<\/p>\n<p>def draw_half_circle():<\/p>\n<p>    fig, ax = plt.subplots()<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u534a\u5706\u5f27\uff0ccenter\u662f\u5706\u5fc3\u5750\u6807\uff0cwidth\u548cheight\u662f\u692d\u5706\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0ctheta1\u548ctheta2\u5206\u522b\u662f\u8d77\u59cb\u89d2\u5ea6\u548c\u7ec8\u6b62\u89d2\u5ea6<\/p>\n<p>    half_circle = Arc((0, 0), width=2, height=2, theta1=0, theta2=180, edgecolor=&#39;blue&#39;)<\/p>\n<p>    ax.add_patch(half_circle)<\/p>\n<p>    ax.set_xlim(-2, 2)<\/p>\n<p>    ax.set_ylim(-2, 2)<\/p>\n<p>    ax.set_aspect(&#39;equal&#39;, &#39;box&#39;)<\/p>\n<p>    plt.grid(True)<\/p>\n<p>    plt.show()<\/p>\n<p>draw_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>Arc\u7c7b<\/strong>\uff1a<code>Arc<\/code>\u7c7b\u7528\u4e8e\u521b\u5efa\u5f27\u5f62\u3002\u53c2\u6570\u5305\u62ec\u5706\u5fc3\u5750\u6807<code>center<\/code>\u3001\u5bbd\u5ea6<code>width<\/code>\u3001\u9ad8\u5ea6<code>height<\/code>\u3001\u8d77\u59cb\u89d2\u5ea6<code>theta1<\/code>\u3001\u7ec8\u6b62\u89d2\u5ea6<code>theta2<\/code>\u3002<\/li>\n<li><strong>add_patch<\/strong>\uff1a<code>ax.add_patch<\/code>\u65b9\u6cd5\u5c06\u521b\u5efa\u7684\u5f27\u5f62\u6dfb\u52a0\u5230\u5b50\u56fe\u4e2d\u3002<\/li>\n<li><strong>set_xlim\u3001set_ylim<\/strong>\uff1a\u7528\u4e8e\u8bbe\u7f6ex\u8f74\u548cy\u8f74\u7684\u663e\u793a\u8303\u56f4\u3002<\/li>\n<li><strong>set_aspect<\/strong>\uff1a\u786e\u4fdd\u56fe\u5f62\u7684\u6a2a\u7eb5\u6bd4\u76f8\u7b49\u3002<\/li>\n<\/ul>\n<p><h4>2. \u534a\u5706\u7684\u586b\u5145<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u586b\u5145\u534a\u5706\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Patch<\/code>\u7c7b\u4e2d\u7684<code>Wedge<\/code>\u7c7b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>from matplotlib.patches import Wedge<\/p>\n<p>def draw_filled_half_circle():<\/p>\n<p>    fig, ax = plt.subplots()<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u586b\u5145\u534a\u5706\uff0ccenter\u662f\u5706\u5fc3\u5750\u6807\uff0cr\u662f\u534a\u5f84\uff0ctheta1\u548ctheta2\u5206\u522b\u662f\u8d77\u59cb\u89d2\u5ea6\u548c\u7ec8\u6b62\u89d2\u5ea6<\/p>\n<p>    filled_half_circle = Wedge((0, 0), r=1, theta1=0, theta2=180, facecolor=&#39;blue&#39;)<\/p>\n<p>    ax.add_patch(filled_half_circle)<\/p>\n<p>    ax.set_xlim(-2, 2)<\/p>\n<p>    ax.set_ylim(-2, 2)<\/p>\n<p>    ax.set_aspect(&#39;equal&#39;, &#39;box&#39;)<\/p>\n<p>    plt.grid(True)<\/p>\n<p>    plt.show()<\/p>\n<p>draw_filled_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528turtle\u5e93\u7ed8\u5236\u534a\u5706<\/h3>\n<\/p>\n<p><p>turtle\u5e93\u662fPython\u7684\u6807\u51c6\u5e93\u4e4b\u4e00\uff0c\u9002\u7528\u4e8e\u7ed8\u5236\u57fa\u672c\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528turtle\u5e93\u7ed8\u5236\u534a\u5706\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import turtle<\/p>\n<p>def draw_half_circle():<\/p>\n<p>    turtle.speed(1)<\/p>\n<p>    turtle.penup()<\/p>\n<p>    turtle.goto(0, 0)<\/p>\n<p>    turtle.pendown()<\/p>\n<p>    turtle.circle(100, 180)  # \u534a\u5f84\u4e3a100\uff0c\u7ed8\u5236180\u5ea6\u7684\u5f27\u7ebf<\/p>\n<p>    turtle.done()<\/p>\n<p>draw_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>turtle.circle(radius, extent)<\/strong>\uff1a<code>circle<\/code>\u65b9\u6cd5\u7528\u4e8e\u7ed8\u5236\u5706\u6216\u5f27\u7ebf\u3002<code>radius<\/code>\u662f\u534a\u5f84\uff0c<code>extent<\/code>\u662f\u7ed8\u5236\u7684\u89d2\u5ea6\u3002<\/li>\n<li><strong>penup\u3001pendown<\/strong>\uff1a\u7528\u4e8e\u62ac\u8d77\u548c\u653e\u4e0b\u753b\u7b14\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001\u4f7f\u7528pygame\u5e93\u7ed8\u5236\u534a\u5706<\/h3>\n<\/p>\n<p><p>pygame\u662f\u4e00\u4e2a\u7528\u4e8e\u5236\u4f5c2D\u6e38\u620f\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u4e5f\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u57fa\u672c\u56fe\u5f62\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528pygame\u5e93\u7ed8\u5236\u534a\u5706\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<p>def draw_half_circle():<\/p>\n<p>    pygame.init()<\/p>\n<p>    screen = pygame.display.set_mode((400, 300))<\/p>\n<p>    pygame.display.set_caption(&#39;Draw Half Circle&#39;)<\/p>\n<p>    # \u8bbe\u7f6e\u989c\u8272<\/p>\n<p>    blue = (0, 0, 255)<\/p>\n<p>    # \u5706\u5fc3\u5750\u6807\u548c\u534a\u5f84<\/p>\n<p>    center = (200, 150)<\/p>\n<p>    radius = 100<\/p>\n<p>    while True:<\/p>\n<p>        for event in pygame.event.get():<\/p>\n<p>            if event.type == pygame.QUIT:<\/p>\n<p>                pygame.quit()<\/p>\n<p>                sys.exit()<\/p>\n<p>        screen.fill((255, 255, 255))<\/p>\n<p>        # \u7ed8\u5236\u534a\u5706<\/p>\n<p>        pygame.draw.arc(screen, blue, [center[0]-radius, center[1]-radius, 2*radius, 2*radius], 0, 3.14159, 2)<\/p>\n<p>        pygame.display.flip()<\/p>\n<p>draw_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8be6\u7ec6\u89e3\u91ca\uff1a<\/strong><\/p>\n<\/p>\n<ul>\n<li><strong>pygame.draw.arc<\/strong>\uff1a\u7528\u4e8e\u7ed8\u5236\u5f27\u7ebf\u3002\u53c2\u6570\u5305\u62ec\u5c4f\u5e55\u5bf9\u8c61<code>screen<\/code>\u3001\u989c\u8272<code>color<\/code>\u3001\u77e9\u5f62\u533a\u57df<code>rect<\/code>\u3001\u8d77\u59cb\u89d2\u5ea6<code>start_angle<\/code>\u3001\u7ec8\u6b62\u89d2\u5ea6<code>stop_angle<\/code>\u3001\u7ebf\u5bbd<code>width<\/code>\u3002<\/li>\n<li><strong>pygame.display.flip()<\/strong>\uff1a\u66f4\u65b0\u5c4f\u5e55\u663e\u793a\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001\u7efc\u5408\u6bd4\u8f83\u4e0e\u5b9e\u9645\u5e94\u7528<\/h3>\n<\/p>\n<p><h4>1. \u6bd4\u8f83\u5404\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9<\/h4>\n<\/p>\n<ul>\n<li><strong>matplotlib<\/strong>\uff1a\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u53ef\u89c6\u5316\u3002\u7ed8\u5236\u7cbe\u5ea6\u9ad8\uff0c\u9002\u5408\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u56fe\u5f62\u3002<\/li>\n<li><strong>turtle<\/strong>\uff1a\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u521d\u5b66\u8005\u548c\u6559\u80b2\u7528\u9014\u3002\u56fe\u5f62\u7cbe\u5ea6\u8f83\u4f4e\uff0c\u4e0d\u9002\u5408\u590d\u6742\u56fe\u5f62\u3002<\/li>\n<li><strong>pygame<\/strong>\uff1a\u9002\u7528\u4e8e\u6e38\u620f\u5f00\u53d1\uff0c\u529f\u80fd\u8f83\u4e3a\u5168\u9762\u3002\u9002\u5408\u5b9e\u65f6\u4ea4\u4e92\u548c\u52a8\u6001\u56fe\u5f62\u3002<\/li>\n<\/ul>\n<p><h4>2. \u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<ul>\n<li><strong>\u6570\u636e\u53ef\u89c6\u5316<\/strong>\uff1a\u5728\u79d1\u5b66\u7814\u7a76\u548c\u6570\u636e\u5206\u6790\u4e2d\uff0c\u4f7f\u7528matplotlib\u7ed8\u5236\u5404\u79cd\u56fe\u5f62\uff0c\u5305\u62ec\u534a\u5706\u3002<\/li>\n<li><strong>\u6559\u80b2\u7528\u9014<\/strong>\uff1a\u4f7f\u7528turtle\u5e93\u6559\u6388\u7f16\u7a0b\u548c\u57fa\u672c\u56fe\u5f62\u7ed8\u5236\u3002<\/li>\n<li><strong>\u6e38\u620f\u5f00\u53d1<\/strong>\uff1a\u57282D\u6e38\u620f\u4e2d\uff0c\u4f7f\u7528pygame\u5e93\u7ed8\u5236\u6e38\u620f\u5143\u7d20\u548c\u56fe\u5f62\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u4ee3\u7801\u4f18\u5316\u4e0e\u6269\u5c55<\/h3>\n<\/p>\n<p><h4>1. \u52a8\u6001\u7ed8\u5236\u534a\u5706<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u5c06\u534a\u5706\u7684\u7ed8\u5236\u8fc7\u7a0b\u52a8\u6001\u5c55\u793a\u51fa\u6765\uff0c\u589e\u5f3a\u7528\u6237\u4f53\u9a8c\u3002\u4ee5\u4e0b\u662fmatplotlib\u52a8\u6001\u7ed8\u5236\u534a\u5706\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>from matplotlib.animation import FuncAnimation<\/p>\n<p>import numpy as np<\/p>\n<p>def draw_dynamic_half_circle():<\/p>\n<p>    fig, ax = plt.subplots()<\/p>\n<p>    ax.set_xlim(-2, 2)<\/p>\n<p>    ax.set_ylim(-2, 2)<\/p>\n<p>    ax.set_aspect(&#39;equal&#39;, &#39;box&#39;)<\/p>\n<p>    plt.grid(True)<\/p>\n<p>    line, = ax.plot([], [], &#39;b-&#39;)<\/p>\n<p>    def init():<\/p>\n<p>        line.set_data([], [])<\/p>\n<p>        return line,<\/p>\n<p>    def update(frame):<\/p>\n<p>        theta = np.linspace(0, np.pi, frame)<\/p>\n<p>        x = np.cos(theta)<\/p>\n<p>        y = np.sin(theta)<\/p>\n<p>        line.set_data(x, y)<\/p>\n<p>        return line,<\/p>\n<p>    ani = FuncAnimation(fig, update, frames=100, init_func=init, blit=True)<\/p>\n<p>    plt.show()<\/p>\n<p>draw_dynamic_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6269\u5c55\u52303D\u534a\u5706<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528matplotlib\u76843D\u7ed8\u56fe\u5e93\u7ed8\u5236\u4e09\u7ef4\u534a\u5706\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/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>from mpl_toolkits.mplot3d import Axes3D<\/p>\n<p>def draw_3d_half_circle():<\/p>\n<p>    fig = plt.figure()<\/p>\n<p>    ax = fig.add_subplot(111, projection=&#39;3d&#39;)<\/p>\n<p>    theta = np.linspace(0, np.pi, 100)<\/p>\n<p>    z = np.linspace(0, 1, 100)<\/p>\n<p>    theta, z = np.meshgrid(theta, z)<\/p>\n<p>    x = np.cos(theta)<\/p>\n<p>    y = np.sin(theta)<\/p>\n<p>    ax.plot_surface(x, y, z, cmap=&#39;viridis&#39;)<\/p>\n<p>    plt.show()<\/p>\n<p>draw_3d_half_circle()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684\u4e0d\u540c\u5e93\u7ed8\u5236\u534a\u5706\u3002<strong>\u5176\u4e2d\uff0cmatplotlib\u5e93\u662f\u6700\u5e38\u7528\u548c\u65b9\u4fbf\u7684\u9009\u62e9<\/strong>\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u80fd\u591f\u8f7b\u677e\u5b9e\u73b0\u5305\u62ec\u534a\u5706\u5728\u5185\u7684\u5404\u79cd\u56fe\u5f62\u7ed8\u5236\u3002turtle\u5e93\u9002\u5408\u521d\u5b66\u8005\uff0c\u800cpygame\u5e93\u9002\u5408\u6e38\u620f\u5f00\u53d1\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u5b9e\u73b0\u56fe\u5f62\u7ed8\u5236\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u7ed8\u5236\u534a\u5706\u7684\u57fa\u672c\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u8981\u4f7f\u7528Python\u7ed8\u5236\u534a\u5706\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u4e00\u4e2a\u56fe\u5f62\u5e93\uff0c\u5982Matplotlib\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>matplotlib.pyplot<\/code>\u6a21\u5757\u4e2d\u7684<code>plot<\/code>\u6216<code>fill<\/code>\u51fd\u6570\u6765\u7ed8\u5236\u534a\u5706\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\u5b9a\u4e49\u534a\u5706\u7684\u53c2\u6570\uff08\u5982\u534a\u5f84\u548c\u4e2d\u5fc3\u5750\u6807\uff09\uff0c\u4f7f\u7528\u6781\u5750\u6807\u6216\u53c2\u6570\u65b9\u7a0b\u751f\u6210\u534a\u5706\u7684\u70b9\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u70b9\u7ed8\u5236\u5230\u56fe\u5f62\u4e2d\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u793a\u4f8b\u4ee3\u7801\u53ef\u4ee5\u53c2\u8003\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u4f7f\u7528Matplotlib\u7ed8\u5236\u534a\u5706\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\n# \u8bbe\u7f6e\u534a\u5f84\u548c\u4e2d\u5fc3\nradius = 1\ntheta = np.linspace(0, np.pi, 100)  # \u751f\u6210\u4ece0\u5230\u03c0\u7684100\u4e2a\u70b9\n\n# \u8ba1\u7b97\u534a\u5706\u7684x\u548cy\u5750\u6807\nx = radius * np.cos(theta)\ny = radius * np.sin(theta)\n\n# \u521b\u5efa\u56fe\u5f62\nplt.figure()\nplt.fill(x, y, &#39;b&#39;)  # \u586b\u5145\u534a\u5706\u4e3a\u84dd\u8272\nplt.xlim(-1.5, 1.5)\nplt.ylim(-0.5, 1.5)\nplt.gca().set_aspect(&#39;equal&#39;)  # \u8bbe\u7f6e\u56fe\u5f62\u6bd4\u4f8b\nplt.title(&#39;Half Circle&#39;)\nplt.show()\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u5c06\u7ed8\u5236\u4e00\u4e2a\u534a\u5f84\u4e3a1\u7684\u84dd\u8272\u534a\u5706\u3002<\/p>\n<p><strong>\u5728\u7ed8\u5236\u534a\u5706\u65f6\u53ef\u4ee5\u6dfb\u52a0\u54ea\u4e9b\u81ea\u5b9a\u4e49\u9009\u9879\uff1f<\/strong><br \/>\u5728\u7ed8\u5236\u534a\u5706\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0\u591a\u79cd\u81ea\u5b9a\u4e49\u9009\u9879\uff0c\u4f8b\u5982\u6539\u53d8\u534a\u5706\u7684\u989c\u8272\u3001\u8fb9\u6846\u6837\u5f0f\u3001\u900f\u660e\u5ea6\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528<code>fill<\/code>\u51fd\u6570\u4e2d\u7684\u53c2\u6570\u6765\u8bbe\u7f6e\u989c\u8272\uff0c\u4f7f\u7528<code>edgecolor<\/code>\u6765\u6307\u5b9a\u8fb9\u6846\u989c\u8272\uff0c<code>alpha<\/code>\u53c2\u6570\u53ef\u4ee5\u8bbe\u7f6e\u586b\u5145\u7684\u900f\u660e\u5ea6\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u5728\u56fe\u4e2d\u6dfb\u52a0\u6807\u9898\u3001\u5750\u6807\u8f74\u6807\u7b7e\u3001\u7f51\u683c\u7ebf\u7b49\uff0c\u4ee5\u589e\u5f3a\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u7ed8\u5236\u7684\u534a\u5706\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Matplotlib\u7ed8\u5236\u534a\u5706\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>savefig<\/code>\u51fd\u6570\u5c06\u56fe\u5f62\u4fdd\u5b58\u4e3a\u56fe\u7247\u6587\u4ef6\u3002\u53ea\u9700\u5728\u7ed8\u56fe\u4ee3\u7801\u7684\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code class=\"language-python\">plt.savefig(&#39;half_circle.png&#39;)  # \u4fdd\u5b58\u4e3aPNG\u683c\u5f0f\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5c06\u5f53\u524d\u56fe\u5f62\u4fdd\u5b58\u4e3a\u6307\u5b9a\u540d\u79f0\u7684\u6587\u4ef6\uff0c\u652f\u6301\u591a\u79cd\u683c\u5f0f\uff0c\u5982PNG\u3001JPEG\u3001PDF\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u7ed8\u5236\u534a\u5706\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528matplotlib\u5e93\u3001\u4f7f\u7528turtle\u5e93\u3001\u4ee5\u53ca [&hellip;]","protected":false},"author":3,"featured_media":1156704,"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\/1156701"}],"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=1156701"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1156701\/revisions"}],"predecessor-version":[{"id":1156707,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1156701\/revisions\/1156707"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1156704"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1156701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1156701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1156701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}