{"id":1092825,"date":"2025-01-08T14:24:59","date_gmt":"2025-01-08T06:24:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1092825.html"},"modified":"2025-01-08T14:25:01","modified_gmt":"2025-01-08T06:25:01","slug":"python-%e5%a6%82%e4%bd%95%e5%b0%86%e6%96%87%e5%ad%97%e7%94%bb%e5%88%b0%e5%9b%be%e4%b8%8a-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1092825.html","title":{"rendered":"python \u5982\u4f55\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24205655\/40fa7f26-c749-4ff2-9af8-646073f3c486.webp\" alt=\"python \u5982\u4f55\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u5e93\u5305\u62ecMatplotlib\u3001Pillow\u548cOpenCV\u3002Matplotlib\u7b80\u5355\u6613\u7528\u3001\u529f\u80fd\u5f3a\u5927\uff0cPillow\u9002\u5408\u56fe\u50cf\u5904\u7406\uff0cOpenCV\u9002\u7528\u4e8e\u8ba1\u7b97\u673a\u89c6\u89c9\u3002<\/strong>\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e09\u79cd\u5e93\u6765\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\uff0c\u5e76\u5bf9Matplotlib\u7684\u4f7f\u7528\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001MATPLOTLIB<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u9002\u7528\u4e8e\u521b\u5efa\u5404\u79cd\u56fe\u8868\u548c\u53ef\u89c6\u5316\u5185\u5bb9\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u5728\u56fe\u4e0a\u6dfb\u52a0\u6587\u5b57\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5Matplotlib<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5Matplotlib\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\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><h3>2. \u57fa\u672c\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Matplotlib\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\u7684\u57fa\u672c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\u4e00\u4e2a\u57fa\u672c\u7684\u7ebf\u6761\u56fe<\/strong><\/h2>\n<p>ax.plot([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<h2><strong>\u5728\u56fe\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>ax.text(2, 10, &#39;Hello, World!&#39;, fontsize=12, color=&#39;red&#39;)<\/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\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u57fa\u672c\u7684\u7ebf\u6761\u56fe\uff0c\u5e76\u5728\u5750\u6807 (2, 10) \u5904\u6dfb\u52a0\u4e86\u4e00\u6bb5\u6587\u5b57 &quot;Hello, World!&quot;\u3002<strong>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>fontsize<\/code>\u548c<code>color<\/code>\u6765\u8c03\u6574\u6587\u5b57\u7684\u5927\u5c0f\u548c\u989c\u8272\u3002<\/strong><\/p>\n<\/p>\n<p><h3>3. \u9ad8\u7ea7\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u66f4\u591a\u7684\u81ea\u5b9a\u4e49\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u56fe\u5f62\u5bf9\u8c61<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u7ed8\u5236\u4e00\u4e2a\u57fa\u672c\u7684\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>ax.scatter([1, 2, 3, 4], [1, 4, 9, 16])<\/p>\n<h2><strong>\u5728\u56fe\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>ax.text(2, 10, &#39;Hello, World!&#39;, fontsize=14, color=&#39;blue&#39;, style=&#39;italic&#39;, weight=&#39;bold&#39;,<\/p>\n<p>        bbox={&#39;facecolor&#39;: &#39;yellow&#39;, &#39;alpha&#39;: 0.5, &#39;pad&#39;: 10})<\/p>\n<h2><strong>\u8bbe\u7f6e\u6807\u9898\u548c\u6807\u7b7e<\/strong><\/h2>\n<p>ax.set_title(&#39;Sample Plot&#39;)<\/p>\n<p>ax.set_xlabel(&#39;X-axis Label&#39;)<\/p>\n<p>ax.set_ylabel(&#39;Y-axis Label&#39;)<\/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\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u6563\u70b9\u56fe\uff0c\u5e76\u5728\u6587\u5b57\u5468\u56f4\u6dfb\u52a0\u4e86\u4e00\u4e2a\u9ec4\u8272\u7684\u80cc\u666f\u6846\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>bbox<\/code>\u53c2\u6570\u6765\u81ea\u5b9a\u4e49\u6587\u5b57\u7684\u80cc\u666f\u6837\u5f0f\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e8c\u3001PILLOW<\/p>\n<\/p>\n<p><p>Pillow\u662fPython Imaging Library\uff08PIL\uff09\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528Pillow\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5Pillow<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5Pillow\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u57fa\u672c\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Pillow\u5c06\u6587\u5b57\u753b\u5230\u56fe\u50cf\u4e0a\u7684\u57fa\u672c\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, 100), color = (73, 109, 137))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u4f7f\u7528\u9ed8\u8ba4\u5b57\u4f53<\/strong><\/h2>\n<p>font = ImageFont.load_default()<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>draw.text((10, 10), &quot;Hello, World!&quot;, fill=(255, 255, 255), font=font)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&#39;pil_text.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\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf\uff0c\u5e76\u5728\u5750\u6807 (10, 10) \u5904\u6dfb\u52a0\u4e86\u4e00\u6bb5\u6587\u5b57 &quot;Hello, World!&quot;\u3002<strong>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>fill<\/code>\u53c2\u6570\u6765\u8c03\u6574\u6587\u5b57\u7684\u989c\u8272\u3002<\/strong><\/p>\n<\/p>\n<p><h3>3. \u9ad8\u7ea7\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u66f4\u591a\u7684\u81ea\u5b9a\u4e49\u9009\u9879\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;, (400, 200), color = (73, 109, 137))<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u5bf9\u8c61<\/strong><\/h2>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u4f7f\u7528\u6307\u5b9a\u5b57\u4f53\u548c\u5927\u5c0f<\/strong><\/h2>\n<p>font = ImageFont.truetype(&quot;arial.ttf&quot;, 36)<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>draw.text((50, 50), &quot;Hello, World!&quot;, fill=(255, 255, 255), font=font)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&#39;pil_text_custom.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\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>truetype<\/code>\u65b9\u6cd5\u6765\u52a0\u8f7d\u6307\u5b9a\u7684\u5b57\u4f53\uff0c\u5e76\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u4e86\u66f4\u5927\u3001\u66f4\u81ea\u5b9a\u4e49\u7684\u6587\u5b57\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e09\u3001OPENCV<\/p>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u8f6f\u4ef6\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528OpenCV\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5OpenCV<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5OpenCV\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u57fa\u672c\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528OpenCV\u5c06\u6587\u5b57\u753b\u5230\u56fe\u50cf\u4e0a\u7684\u57fa\u672c\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = np.zeros((200, 400, 3), dtype=np.uint8)<\/p>\n<h2><strong>\u8bbe\u7f6e\u6587\u5b57\u548c\u4f4d\u7f6e<\/strong><\/h2>\n<p>text = &quot;Hello, World!&quot;<\/p>\n<p>org = (50, 100)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b57\u4f53\u3001\u5927\u5c0f\u548c\u989c\u8272<\/strong><\/h2>\n<p>font = cv2.FONT_HERSHEY_SIMPLEX<\/p>\n<p>font_scale = 1<\/p>\n<p>color = (255, 255, 255)<\/p>\n<h2><strong>\u8bbe\u7f6e\u7ebf\u6761\u7c97\u7ec6<\/strong><\/h2>\n<p>thickness = 2<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>cv2.putText(image, text, org, font, font_scale, color, thickness, cv2.LINE_AA)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;opencv_text.png&#39;, image)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image&#39;, image)<\/p>\n<p>cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>cv2.putText<\/code>\u65b9\u6cd5\u5728\u5750\u6807 (50, 100) \u5904\u6dfb\u52a0\u4e86\u4e00\u6bb5\u6587\u5b57 &quot;Hello, World!&quot;\u3002<strong>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>fontScale<\/code>\u3001<code>color<\/code>\u548c<code>thickness<\/code>\u53c2\u6570\u6765\u8c03\u6574\u6587\u5b57\u7684\u5927\u5c0f\u3001\u989c\u8272\u548c\u7c97\u7ec6\u3002<\/strong><\/p>\n<\/p>\n<p><h3>3. \u9ad8\u7ea7\u793a\u4f8b<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u66f4\u591a\u7684\u81ea\u5b9a\u4e49\u9009\u9879\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = np.zeros((400, 800, 3), dtype=np.uint8)<\/p>\n<h2><strong>\u8bbe\u7f6e\u6587\u5b57\u548c\u4f4d\u7f6e<\/strong><\/h2>\n<p>text = &quot;OpenCV Text Example&quot;<\/p>\n<p>org = (50, 200)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b57\u4f53\u3001\u5927\u5c0f\u548c\u989c\u8272<\/strong><\/h2>\n<p>font = cv2.FONT_HERSHEY_COMPLEX<\/p>\n<p>font_scale = 2<\/p>\n<p>color = (0, 255, 0)<\/p>\n<h2><strong>\u8bbe\u7f6e\u7ebf\u6761\u7c97\u7ec6<\/strong><\/h2>\n<p>thickness = 3<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e0a\u6dfb\u52a0\u6587\u5b57<\/strong><\/h2>\n<p>cv2.putText(image, text, org, font, font_scale, color, thickness, cv2.LINE_AA)<\/p>\n<h2><strong>\u753b\u4e00\u4e2a\u77e9\u5f62\u6846\u6765\u5c55\u793a\u6587\u5b57\u80cc\u666f<\/strong><\/h2>\n<p>cv2.rectangle(image, (45, 180), (755, 230), (255, 0, 0), 2)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;opencv_text_custom.png&#39;, image)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image&#39;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u66f4\u590d\u6742\u7684\u5b57\u4f53\u6837\u5f0f\uff0c\u5e76\u5728\u6587\u5b57\u5468\u56f4\u6dfb\u52a0\u4e86\u4e00\u4e2a\u84dd\u8272\u7684\u77e9\u5f62\u6846\u3002<\/p>\n<\/p>\n<hr>\n<p><p><strong>\u603b\u7ed3<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u6765\u5b9e\u73b0\uff0c<strong>Matplotlib\u3001Pillow\u548cOpenCV\u662f\u6700\u5e38\u7528\u7684\u4e09\u79cd\u65b9\u6cd5<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f\u3002<strong>Matplotlib\u9002\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\uff0cPillow\u9002\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff0cOpenCV\u9002\u7528\u4e8e\u8ba1\u7b97\u673a\u89c6\u89c9\u3002<\/strong>\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528Matplotlib\u6dfb\u52a0\u6587\u5b57\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6587\u5b57\u6dfb\u52a0\u5230\u56fe\u8868\u4e0a\u3002\u53ef\u4ee5\u901a\u8fc7<code>plt.text()<\/code>\u51fd\u6570\u6765\u5b9e\u73b0\uff0c\u60a8\u9700\u8981\u6307\u5b9a\u6587\u5b57\u7684\u4f4d\u7f6e\u3001\u5185\u5bb9\u4ee5\u53ca\u5176\u4ed6\u6837\u5f0f\u53c2\u6570\uff0c\u5982\u5b57\u4f53\u5927\u5c0f\u548c\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nplt.plot([1, 2, 3], [4, 5, 6])\nplt.text(2, 5, &#39;\u8fd9\u91cc\u662f\u6587\u5b57&#39;, fontsize=12, color=&#39;red&#39;)\nplt.show()\n<\/code><\/pre>\n<p><strong>\u53ef\u4ee5\u5728\u56fe\u8868\u7684\u54ea\u4e9b\u4f4d\u7f6e\u6dfb\u52a0\u6587\u5b57\uff1f<\/strong><br \/>\u53ef\u4ee5\u5728\u56fe\u8868\u7684\u4efb\u610f\u4f4d\u7f6e\u6dfb\u52a0\u6587\u5b57\uff0c\u901a\u5e38\u4f7f\u7528\u5750\u6807\u8f74\u7684\u6570\u503c\u6765\u786e\u5b9a\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u70b9\u3001\u5750\u6807\u8f74\u7684\u8fb9\u754c\u6216\u56fe\u8868\u7684\u4e2d\u5fc3\u7b49\u5730\u65b9\u6dfb\u52a0\u6587\u5b57\u3002\u901a\u8fc7\u8c03\u6574<code>plt.text()<\/code>\u4e2d\u7684x\u548cy\u53c2\u6570\uff0c\u53ef\u4ee5\u7cbe\u786e\u63a7\u5236\u6587\u5b57\u7684\u663e\u793a\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u6dfb\u52a0\u6587\u5b57\u65f6\u53ef\u4ee5\u8c03\u6574\u54ea\u4e9b\u6837\u5f0f\uff1f<\/strong><br \/>\u5728\u6dfb\u52a0\u6587\u5b57\u65f6\uff0c\u53ef\u4ee5\u8c03\u6574\u591a\u79cd\u6837\u5f0f\uff0c\u5305\u62ec\u5b57\u4f53\u3001\u5927\u5c0f\u3001\u989c\u8272\u3001\u5bf9\u9f50\u65b9\u5f0f\u7b49\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>fontsize<\/code>\u53c2\u6570\u8c03\u6574\u6587\u5b57\u5927\u5c0f\uff0c<code>color<\/code>\u53c2\u6570\u8bbe\u7f6e\u989c\u8272\uff0c<code>ha<\/code>\u548c<code>va<\/code>\u53c2\u6570\u5206\u522b\u63a7\u5236\u6c34\u5e73\u548c\u5782\u76f4\u5bf9\u9f50\u65b9\u5f0f\u3002\u8fd9\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49\u6587\u5b57\u7684\u5916\u89c2\uff0c\u589e\u5f3a\u56fe\u8868\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u6587\u5b57\u753b\u5230\u56fe\u4e0a\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u5e93\u5305\u62ecMatplotlib\u3001Pillow\u548cOpe [&hellip;]","protected":false},"author":3,"featured_media":1092832,"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\/1092825"}],"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=1092825"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1092825\/revisions"}],"predecessor-version":[{"id":1092833,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1092825\/revisions\/1092833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1092832"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1092825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1092825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1092825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}