{"id":954458,"date":"2024-12-27T01:57:48","date_gmt":"2024-12-26T17:57:48","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/954458.html"},"modified":"2024-12-27T01:57:51","modified_gmt":"2024-12-26T17:57:51","slug":"%e5%a6%82%e4%bd%95python%e8%ae%be%e7%bd%ae%e7%94%bb%e5%9b%be%e5%b0%ba%e5%af%b8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/954458.html","title":{"rendered":"\u5982\u4f55python\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094655\/7c35816e-df16-45cd-948c-4120488f2840.webp\" alt=\"\u5982\u4f55python\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8\u901a\u5e38\u6d89\u53ca\u4f7f\u7528matplotlib\u5e93\u3002<strong>\u901a\u8fc7\u4f7f\u7528matplotlib\u5e93\u7684<code>figure()<\/code>\u51fd\u6570\u3001<code>subplots()<\/code>\u51fd\u6570\u4ee5\u53ca\u8bbe\u7f6e<code>rcParams<\/code>\u5c5e\u6027\u53ef\u4ee5\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8\u3002<\/strong>\u5176\u4e2d\uff0c<code>figure()<\/code>\u51fd\u6570\u548c<code>subplots()<\/code>\u51fd\u6570\u63d0\u4f9b\u4e86\u901a\u8fc7\u53c2\u6570\u76f4\u63a5\u8bbe\u7f6e\u56fe\u5f62\u5c3a\u5bf8\u7684\u65b9\u6cd5\uff0c\u800c<code>rcParams<\/code>\u5c5e\u6027\u5219\u5141\u8bb8\u60a8\u5168\u5c40\u8bbe\u7f6e\u9ed8\u8ba4\u56fe\u5f62\u5c3a\u5bf8\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>figure()<\/code>\u51fd\u6570\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8<\/h3>\n<\/p>\n<p><p><code>figure()<\/code>\u51fd\u6570\u662fmatplotlib\u4e2d\u521b\u5efa\u56fe\u5f62\u7684\u57fa\u672c\u65b9\u6cd5\u4e4b\u4e00\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u4f20\u9012<code>figsize<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002<code>figsize<\/code>\u662f\u4e00\u4e2a\u5305\u542b\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5143\u7ec4\uff0c\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d\u3002<\/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\uff0c\u5e76\u8bbe\u7f6e\u5c3a\u5bf8\u4e3a8x6\u82f1\u5bf8<\/strong><\/h2>\n<p>plt.figure(figsize=(8, 6))<\/p>\n<p>plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>plt.title(&quot;Example Plot&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u56fe\u5f62\u5355\u72ec\u8bbe\u7f6e\u5c3a\u5bf8\u3002\u8fd9\u79cd\u65b9\u6cd5\u7075\u6d3b\u6027\u8f83\u9ad8\uff0c\u9002\u5408\u9700\u8981\u5bf9\u6bcf\u4e2a\u56fe\u5f62\u8fdb\u884c\u4e2a\u6027\u5316\u8bbe\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528<code>subplots()<\/code>\u51fd\u6570\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8<\/h3>\n<\/p>\n<p><p><code>subplots()<\/code>\u51fd\u6570\u662fmatplotlib\u4e2d\u7528\u4e8e\u521b\u5efa\u4e00\u7ec4\u5b50\u56fe\u7684\u65b9\u6cd5\u3002\u5b83\u4e5f\u5141\u8bb8\u901a\u8fc7<code>figsize<\/code>\u53c2\u6570\u8bbe\u7f6e\u6574\u4f53\u56fe\u5f62\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b50\u56fe\u7684\u56fe\u5f62\uff0c\u5e76\u8bbe\u7f6e\u5c3a\u5bf8<\/strong><\/h2>\n<p>fig, axes = plt.subplots(2, 2, figsize=(10, 8))<\/p>\n<p>axes[0, 0].plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>axes[0, 1].plot([1, 2, 3], [6, 5, 4])<\/p>\n<p>axes[1, 0].plot([1, 2, 3], [4, 6, 5])<\/p>\n<p>axes[1, 1].plot([1, 2, 3], [5, 4, 6])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>subplots()<\/code>\u51fd\u6570\u53ef\u4ee5\u65b9\u4fbf\u5730\u540c\u65f6\u521b\u5efa\u591a\u4e2a\u5b50\u56fe\uff0c\u5e76\u7edf\u4e00\u63a7\u5236\u6574\u4f53\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528<code>rcParams<\/code>\u8bbe\u7f6e\u5168\u5c40\u9ed8\u8ba4\u5c3a\u5bf8<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u5e0c\u671b\u5728\u6574\u4e2a\u4f1a\u8bdd\u4e2d\u4f7f\u7528\u7edf\u4e00\u7684\u56fe\u5f62\u5c3a\u5bf8\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6ematplotlib\u7684<code>rcParams<\/code>\u6765\u5b9e\u73b0\u3002<code>rcParams<\/code>\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u5141\u8bb8\u8bbe\u7f6e\u5404\u79cd\u5168\u5c40\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u8bbe\u7f6e\u5168\u5c40\u9ed8\u8ba4\u56fe\u5f62\u5c3a\u5bf8<\/strong><\/h2>\n<p>plt.rcParams[&#39;figure.figsize&#39;] = (12, 9)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62\u65f6\u5c06\u81ea\u52a8\u4f7f\u7528\u9ed8\u8ba4\u5c3a\u5bf8<\/strong><\/h2>\n<p>plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>plt.title(&quot;Default Size Plot&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u5728\u4e00\u4e2a\u811a\u672c\u6216\u9879\u76ee\u4e2d\u9700\u8981\u4fdd\u6301\u4e00\u81f4\u56fe\u5f62\u5c3a\u5bf8\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5355\u4f4d<\/strong>\uff1a\u5728matplotlib\u4e2d\uff0c\u56fe\u5f62\u5c3a\u5bf8\u662f\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d\u7684\uff0c\u56e0\u6b64\u5728\u8bbe\u7f6e\u5c3a\u5bf8\u65f6\u8981\u6ce8\u610f\u8fd9\u4e00\u70b9\u3002\u663e\u793a\u8bbe\u5907\u7684\u5206\u8fa8\u7387\uff08DPI, Dots Per Inch\uff09\u4e5f\u4f1a\u5f71\u54cd\u6700\u7ec8\u7684\u8f93\u51fa\u6548\u679c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u6301\u6bd4\u4f8b<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4fdd\u6301\u56fe\u5f62\u6bd4\u4f8b\u53ef\u80fd\u5f88\u91cd\u8981\u3002\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u5bbd\u9ad8\u6bd4\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9002\u5e94\u8f93\u51fa\u8bbe\u5907<\/strong>\uff1a\u4e0d\u540c\u7684\u8f93\u51fa\u8bbe\u5907\uff08\u5982\u5c4f\u5e55\u663e\u793a\u6216\u6253\u5370\uff09\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u6700\u4f73\u56fe\u5f62\u5c3a\u5bf8\u3002\u6839\u636e\u6700\u7ec8\u7528\u9014\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\u662f\u503c\u5f97\u8003\u8651\u7684\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6e05\u6670\u5ea6<\/strong>\uff1a\u5982\u679c\u56fe\u5f62\u9700\u8981\u653e\u5927\u663e\u793a\u6216\u6253\u5370\uff0c\u786e\u4fdd\u56fe\u5f62\u7684\u5206\u8fa8\u7387\uff08DPI\uff09\u8db3\u591f\u9ad8\u4ee5\u907f\u514d\u6a21\u7cca\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e\u56fe\u5f62\u5c3a\u5bf8\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u53ef\u89c6\u5316\u7684\u6548\u679c\u548c\u53ef\u8bfb\u6027\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u548c\u53c2\u6570\u53ef\u4ee5\u4f7f\u5f97\u56fe\u5f62\u66f4\u4e3a\u7f8e\u89c2\u548c\u4e13\u4e1a\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u81ea\u5b9a\u4e49\u56fe\u5f62\u7684\u5927\u5c0f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002\u901a\u8fc7<code>plt.figure(figsize=(width, height))<\/code>\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u6307\u5b9a\u56fe\u5f62\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u5355\u4f4d\u662f\u82f1\u5bf8\u3002\u4f8b\u5982\uff0c<code>plt.figure(figsize=(10, 5))<\/code>\u5c06\u521b\u5efa\u4e00\u4e2a\u5bbd10\u82f1\u5bf8\u3001\u9ad85\u82f1\u5bf8\u7684\u56fe\u5f62\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528Seaborn\u65f6\u5982\u4f55\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\uff1f<\/strong><br \/>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u53ef\u89c6\u5316\u5e93\u3002\u5728Seaborn\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>plt.figure(figsize=(width, height))<\/code>\u6765\u8bbe\u7f6e\u56fe\u5f62\u5c3a\u5bf8\uff0c\u6216\u8005\u4f7f\u7528<code>sns.set(figsize=(width, height))<\/code>\u65b9\u6cd5\u8c03\u6574\u6574\u4e2a\u7ed8\u56fe\u7684\u9ed8\u8ba4\u5c3a\u5bf8\u3002\u8fd9\u4f7f\u5f97\u5728\u7ed8\u5236\u591a\u5f20\u56fe\u65f6\u4fdd\u6301\u4e00\u81f4\u6027\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002<\/p>\n<p><strong>\u8bbe\u7f6e\u56fe\u5f62\u5c3a\u5bf8\u5bf9\u53ef\u89c6\u5316\u6548\u679c\u6709\u4ec0\u4e48\u5f71\u54cd\uff1f<\/strong><br \/>\u56fe\u5f62\u7684\u5c3a\u5bf8\u4f1a\u76f4\u63a5\u5f71\u54cd\u6570\u636e\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u89c6\u5316\u6548\u679c\u3002\u8f83\u5927\u7684\u56fe\u5f62\u53ef\u4ee5\u66f4\u6e05\u6670\u5730\u5c55\u793a\u590d\u6742\u7684\u6570\u636e\u5173\u7cfb\uff0c\u800c\u8f83\u5c0f\u7684\u56fe\u5f62\u5219\u9002\u5408\u7b80\u5355\u7684\u5c55\u793a\u3002\u901a\u8fc7\u9002\u5f53\u7684\u5c3a\u5bf8\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u63d0\u9ad8\u56fe\u5f62\u7684\u53ef\u89c6\u5316\u6548\u679c\uff0c\u4f7f\u6570\u636e\u7684\u8d8b\u52bf\u548c\u6a21\u5f0f\u66f4\u52a0\u663e\u8457\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8bbe\u7f6e\u753b\u56fe\u5c3a\u5bf8\u901a\u5e38\u6d89\u53ca\u4f7f\u7528matplotlib\u5e93\u3002\u901a\u8fc7\u4f7f\u7528matplotlib\u5e93\u7684figure( [&hellip;]","protected":false},"author":3,"featured_media":954464,"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\/954458"}],"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=954458"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954458\/revisions"}],"predecessor-version":[{"id":954465,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954458\/revisions\/954465"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/954464"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=954458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=954458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=954458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}