{"id":1034423,"date":"2024-12-31T11:50:06","date_gmt":"2024-12-31T03:50:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1034423.html"},"modified":"2024-12-31T11:50:08","modified_gmt":"2024-12-31T03:50:08","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e7%9c%8b%e7%9b%b4%e6%96%b9%e5%9b%be%e5%92%8cqq%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1034423.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u770b\u76f4\u65b9\u56fe\u548cqq\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/7d21e236-6b44-4dfa-b88b-cd902f51b250.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u4e2d\u5982\u4f55\u770b\u76f4\u65b9\u56fe\u548cqq\u56fe\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u67e5\u770b\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u7ed8\u5236\u76f4\u65b9\u56fe\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u76f4\u65b9\u56fe\u3001\u4f7f\u7528SciPy\u7ed8\u5236QQ\u56fe\u3001\u7406\u89e3\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u7528\u9014<\/strong>\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e00\u4e0b\u5176\u4e2d\u4e00\u4e2a\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528Matplotlib\u7ed8\u5236\u76f4\u65b9\u56fe\u3002<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u7edf\u8ba1\u5b66\u4e2d\uff0c\u76f4\u65b9\u56fe\u548cQQ\u56fe\u662f\u5e38\u7528\u7684\u53ef\u89c6\u5316\u5de5\u5177\u3002<strong>\u76f4\u65b9\u56fe\u7528\u4e8e\u663e\u793a\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5<\/strong>\uff0c\u800c<strong>QQ\u56fe\u7528\u4e8e\u68c0\u67e5\u6570\u636e\u662f\u5426\u7b26\u5408\u67d0\u4e2a\u5206\u5e03\uff0c\u4f8b\u5982\u6b63\u6001\u5206\u5e03<\/strong>\u3002\u901a\u8fc7\u8fd9\u4e9b\u56fe\u8868\uff0c\u6570\u636e\u5206\u6790\u5e08\u53ef\u4ee5\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u6570\u636e\u7684\u7279\u6027\u548c\u8d8b\u52bf\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001MATPLOTLIB\u7ed8\u5236\u76f4\u65b9\u56fe<\/h3>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u7ed8\u56fe\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u5404\u79cd\u56fe\u8868\uff0c\u5305\u62ec\u76f4\u65b9\u56fe\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5Matplotlib<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Matplotlib\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\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><h4>2\u3001\u5bfc\u5165Matplotlib\u5e93\u5e76\u7ed8\u5236\u76f4\u65b9\u56fe<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e9b\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.randn(1000)<\/p>\n<h2><strong>\u7ed8\u5236\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>plt.hist(data, bins=30, edgecolor=&#39;black&#39;)<\/p>\n<p>plt.title(&#39;Histogram of Normally Distributed Data&#39;)<\/p>\n<p>plt.xlabel(&#39;Value&#39;)<\/p>\n<p>plt.ylabel(&#39;Frequency&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u751f\u6210\u4e86\u4e00\u4e9b\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528<code>plt.hist()<\/code>\u51fd\u6570\u7ed8\u5236\u76f4\u65b9\u56fe\u3002<code>bins<\/code>\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u76f4\u65b9\u56fe\u7684\u67f1\u5b50\u6570\u91cf\uff0c<code>edgecolor<\/code>\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u67f1\u5b50\u7684\u8fb9\u7f18\u989c\u8272\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001SEABORN\u7ed8\u5236\u76f4\u65b9\u56fe<\/h3>\n<\/p>\n<p><p>Seaborn\u662f\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u548c\u7f8e\u89c2\u7684\u63a5\u53e3\u6765\u7ed8\u5236\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5Seaborn<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Seaborn\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install seaborn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5bfc\u5165Seaborn\u5e76\u7ed8\u5236\u76f4\u65b9\u56fe<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e9b\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.randn(1000)<\/p>\n<h2><strong>\u4f7f\u7528Seaborn\u7ed8\u5236\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>sns.histplot(data, bins=30, kde=True)<\/p>\n<p>plt.title(&#39;Histogram with KDE of Normally Distributed Data&#39;)<\/p>\n<p>plt.xlabel(&#39;Value&#39;)<\/p>\n<p>plt.ylabel(&#39;Frequency&#39;)<\/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\u7528Seaborn\u7684<code>histplot()<\/code>\u51fd\u6570\u7ed8\u5236\u76f4\u65b9\u56fe\uff0c\u5e76\u901a\u8fc7\u8bbe\u7f6e<code>kde=True<\/code>\u6765\u6dfb\u52a0\u6838\u5bc6\u5ea6\u4f30\u8ba1\u66f2\u7ebf\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001SCIPY\u7ed8\u5236QQ\u56fe<\/h3>\n<\/p>\n<p><p>QQ\u56fe\uff08Quantile-Quantile Plot\uff09\u7528\u4e8e\u6bd4\u8f83\u6570\u636e\u7684\u5206\u5e03\u4e0e\u7406\u8bba\u5206\u5e03\u662f\u5426\u4e00\u81f4\u3002SciPy\u5e93\u63d0\u4f9b\u4e86\u7ed8\u5236QQ\u56fe\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5SciPy<\/h4>\n<\/p>\n<p><p>\u9996\u5148\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86SciPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5bfc\u5165SciPy\u5e76\u7ed8\u5236QQ\u56fe<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy.stats as stats<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u4e00\u4e9b\u6570\u636e<\/strong><\/h2>\n<p>data = np.random.randn(1000)<\/p>\n<h2><strong>\u7ed8\u5236QQ\u56fe<\/strong><\/h2>\n<p>stats.probplot(data, dist=&quot;norm&quot;, plot=plt)<\/p>\n<p>plt.title(&#39;QQ Plot of Normally Distributed Data&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c<code>stats.probplot()<\/code>\u51fd\u6570\u7528\u4e8e\u7ed8\u5236QQ\u56fe\uff0c\u5176\u4e2d<code>dist=&quot;norm&quot;<\/code>\u8868\u793a\u6211\u4eec\u5047\u8bbe\u6570\u636e\u7b26\u5408\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7406\u89e3\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u7528\u9014<\/h3>\n<\/p>\n<p><h4>1\u3001\u76f4\u65b9\u56fe<\/h4>\n<\/p>\n<p><p><strong>\u76f4\u65b9\u56fe<\/strong>\u662f\u4e00\u79cd\u67f1\u72b6\u56fe\uff0c\u7528\u4e8e\u5c55\u793a\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u3002\u901a\u8fc7\u76f4\u65b9\u56fe\uff0c\u6211\u4eec\u53ef\u4ee5\u4e86\u89e3\u6570\u636e\u7684\u96c6\u4e2d\u8d8b\u52bf\u3001\u79bb\u6563\u7a0b\u5ea6\u4ee5\u53ca\u5206\u5e03\u5f62\u72b6\u3002\u4f8b\u5982\uff0c\u5728\u6b63\u6001\u5206\u5e03\u7684\u76f4\u65b9\u56fe\u4e2d\uff0c\u6570\u636e\u5448\u949f\u5f62\u5206\u5e03\uff0c\u5927\u90e8\u5206\u6570\u636e\u96c6\u4e2d\u5728\u5747\u503c\u9644\u8fd1\uff0c\u968f\u7740\u6570\u636e\u504f\u79bb\u5747\u503c\uff0c\u9891\u7387\u9010\u6e10\u964d\u4f4e\u3002<\/p>\n<\/p>\n<p><h4>2\u3001QQ\u56fe<\/h4>\n<\/p>\n<p><p><strong>QQ\u56fe<\/strong>\u662f\u4e00\u79cd\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5206\u5e03\u7684\u56fe\u8868\u3002\u901a\u8fc7QQ\u56fe\uff0c\u6211\u4eec\u53ef\u4ee5\u5224\u65ad\u6570\u636e\u662f\u5426\u7b26\u5408\u67d0\u4e2a\u7406\u8bba\u5206\u5e03\uff08\u4f8b\u5982\u6b63\u6001\u5206\u5e03\uff09\u3002\u5728QQ\u56fe\u4e2d\uff0c\u82e5\u6570\u636e\u70b9\u5927\u81f4\u6cbf\u5bf9\u89d2\u7ebf\u5206\u5e03\uff0c\u8bf4\u660e\u6570\u636e\u7b26\u5408\u8be5\u7406\u8bba\u5206\u5e03\u3002\u82e5\u6570\u636e\u70b9\u504f\u79bb\u5bf9\u89d2\u7ebf\uff0c\u8bf4\u660e\u6570\u636e\u4e0d\u7b26\u5408\u8be5\u7406\u8bba\u5206\u5e03\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u7edf\u8ba1\u5b66\u4e2d\uff0c\u76f4\u65b9\u56fe\u548cQQ\u56fe\u662f\u5e38\u7528\u7684\u53ef\u89c6\u5316\u5de5\u5177\u3002\u901a\u8fc7Matplotlib\u3001Seaborn\u548cSciPy\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ed8\u5236\u76f4\u65b9\u56fe\u548cQQ\u56fe\uff0c\u4ece\u800c\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u548c\u7279\u6027\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f7f\u7528\u76f4\u65b9\u56fe\u548cQQ\u56fe\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5efa\u6a21\uff0c\u63d0\u5347\u6570\u636e\u5904\u7406\u548c\u51b3\u7b56\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u7ed8\u5236\u76f4\u65b9\u56fe\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u8f7b\u677e\u7ed8\u5236\u76f4\u65b9\u56fe\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5Matplotlib\u5e93\u5e76\u5bfc\u5165\u5b83\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>plt.hist()<\/code>\u51fd\u6570\u4f20\u5165\u60a8\u7684\u6570\u636e\u96c6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u8bbe\u7f6e\u76f4\u65b9\u56fe\u7684\u6837\u5f0f\u3001\u989c\u8272\u548c\u5206\u7bb1\u6570\u91cf\u3002\u8fd0\u884c\u4ee3\u7801\u540e\uff0c\u4f7f\u7528<code>plt.show()<\/code>\u6765\u5c55\u793a\u56fe\u5f62\u3002<\/p>\n<p><strong>QQ\u56fe\u5728Python\u4e2d\u6709\u4ec0\u4e48\u7528\u5904\uff1f<\/strong><br \/>QQ\u56fe\uff08Quantile-Quantile Plot\uff09\u662f\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u7684\u5de5\u5177\uff0c\u7279\u522b\u662f\u7528\u6765\u68c0\u67e5\u6570\u636e\u7684\u6b63\u6001\u6027\u3002\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528SciPy\u5e93\u7684<code>scipy.stats.probplot()<\/code>\u51fd\u6570\u6765\u751f\u6210QQ\u56fe\u3002\u901a\u8fc7\u89c2\u5bdf\u6570\u636e\u70b9\u4e0e\u7406\u8bba\u7ebf\u7684\u63a5\u8fd1\u7a0b\u5ea6\uff0c\u60a8\u53ef\u4ee5\u5224\u65ad\u6570\u636e\u662f\u5426\u7b26\u5408\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u81ea\u5b9a\u4e49\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u6837\u5f0f\uff1f<\/strong><br \/>\u4e3a\u4e86\u81ea\u5b9a\u4e49\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u6837\u5f0f\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7Matplotlib\u548cSeaborn\u5e93\u6765\u8c03\u6574\u56fe\u5f62\u7684\u5c5e\u6027\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6539\u53d8\u989c\u8272\u3001\u6dfb\u52a0\u6807\u9898\u3001\u8c03\u6574\u5750\u6807\u8f74\u6807\u7b7e\u548c\u523b\u5ea6\u7b49\u3002\u5728\u7ed8\u5236\u76f4\u65b9\u56fe\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>plt.title()<\/code>\u548c<code>plt.xlabel()<\/code>\u7b49\u51fd\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u6807\u9898\u548c\u6807\u7b7e\u3002\u5bf9\u4e8eQQ\u56fe\uff0c\u60a8\u540c\u6837\u53ef\u4ee5\u901a\u8fc7Matplotlib\u63d0\u4f9b\u7684\u529f\u80fd\u6765\u7f8e\u5316\u56fe\u5f62\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u67e5\u770b\u76f4\u65b9\u56fe\u548cQQ\u56fe\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Matplotlib\u7ed8\u5236\u76f4\u65b9\u56fe\u3001\u4f7f\u7528Seaborn\u7ed8\u5236\u76f4\u65b9\u56fe\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1034434,"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\/1034423"}],"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=1034423"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1034423\/revisions"}],"predecessor-version":[{"id":1034439,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1034423\/revisions\/1034439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1034434"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1034423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1034423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1034423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}