{"id":1014377,"date":"2024-12-27T11:55:45","date_gmt":"2024-12-27T03:55:45","guid":{"rendered":""},"modified":"2024-12-27T11:55:48","modified_gmt":"2024-12-27T03:55:48","slug":"python%e5%a6%82%e4%bd%95%e7%94%bb%e6%9b%bc%e5%93%88%e9%a1%bf%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1014377.html","title":{"rendered":"python\u5982\u4f55\u753b\u66fc\u54c8\u987f\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094526\/6b2513bd-9017-4d52-a25b-86e6ba41181c.webp\" alt=\"python\u5982\u4f55\u753b\u66fc\u54c8\u987f\u56fe\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u753b\u66fc\u54c8\u987f\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u7ed8\u56fe\u5e93\u3001\u51c6\u5907\u6570\u636e\u3001\u8bbe\u7f6e\u56fe\u5f62\u53c2\u6570\u3001\u7ed8\u5236\u56fe\u5f62\u3001\u4f18\u5316\u53ef\u89c6\u5316\u6548\u679c<\/strong>\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e2a\u4f7f\u7528Python\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u7684\u5b8c\u6574\u793a\u4f8b\u3002<\/p>\n<\/p>\n<hr>\n<h2><strong>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u7ed8\u56fe\u5e93<\/strong><\/h2>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u7ed8\u56fe\u5e93\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u5305\u62ecMatplotlib\u3001Seaborn\u548cPlotly\u3002\u6bcf\u4e2a\u5e93\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>Matplotlib<\/strong>\uff1a\u57fa\u7840\u7684\u7ed8\u56fe\u5e93\uff0c\u7075\u6d3b\u6027\u9ad8\uff0c\u9002\u5408\u9700\u8981\u81ea\u5b9a\u4e49\u56fe\u5f62\u7ec6\u8282\u7684\u7528\u6237\u3002<\/li>\n<li><strong>Seaborn<\/strong>\uff1a\u57fa\u4e8eMatplotlib\uff0c\u63d0\u4f9b\u66f4\u9ad8\u7ea7\u7684\u63a5\u53e3\u548c\u9ed8\u8ba4\u6837\u5f0f\uff0c\u9002\u5408\u5feb\u901f\u7ed8\u5236\u7f8e\u89c2\u56fe\u5f62\u3002<\/li>\n<li><strong>Plotly<\/strong>\uff1a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u9002\u5408\u9700\u8981\u4ea4\u4e92\u529f\u80fd\u7684\u56fe\u5f62\u3002<\/li>\n<\/ol>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Matplotlib\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\uff0c\u56e0\u4e3a\u5b83\u662f\u6700\u57fa\u7840\u4e14\u7075\u6d3b\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p><p>\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u7684\u7b2c\u4e00\u6b65\u662f\u51c6\u5907\u6570\u636e\u3002\u901a\u5e38\uff0c\u8fd9\u6d89\u53ca\u57fa\u56e0\u7ec4\u7814\u7a76\u4e2d\u7684p\u503c\u6570\u636e\u3002\u6570\u636e\u901a\u5e38\u5305\u62ec\u67d3\u8272\u4f53\u7f16\u53f7\u3001\u4f4d\u7f6e\u548c\u5bf9\u5e94\u7684p\u503c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u683c\u5f0f<\/strong>\uff1a\u6570\u636e\u5e94\u5305\u62ec\u67d3\u8272\u4f53\u7f16\u53f7\uff08\u901a\u5e38\u4e3a\u6570\u5b57\u6216\u5b57\u7b26\u4e32\uff09\u3001\u57fa\u56e0\u7ec4\u4f4d\u7f6e\uff08\u901a\u5e38\u4e3a\u6574\u6570\uff09\u548cp\u503c\uff08\u901a\u5e38\u4e3a\u6d6e\u70b9\u6570\uff09\u3002<\/li>\n<li><strong>\u6570\u636e\u5bfc\u5165<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u6765\u5bfc\u5165\u548c\u5904\u7406\u6570\u636e\u3002Pandas\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\uff0c\u5982CSV\u3001Excel\u7b49\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aCSV\u6587\u4ef6\uff0c\u5305\u542bchromosome, position, pvalue\u5217<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;genome_data.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6570\u636e\u9884\u5904\u7406<\/strong>\uff1a\u68c0\u67e5\u6570\u636e\u4e2d\u7684\u7f3a\u5931\u503c\u6216\u5f02\u5e38\u503c\uff0c\u5e76\u8fdb\u884c\u5fc5\u8981\u7684\u6e05\u6d17\u6216\u8f6c\u6362\u3002<\/li>\n<\/ol>\n<h2><strong>\u4e09\u3001\u8bbe\u7f6e\u56fe\u5f62\u53c2\u6570<\/strong><\/h2>\n<p><p>\u5728\u7ed8\u5236\u4e4b\u524d\uff0c\u9700\u8981\u8bbe\u7f6e\u4e00\u4e9b\u57fa\u672c\u7684\u56fe\u5f62\u53c2\u6570\uff0c\u5982\u56fe\u5f62\u5927\u5c0f\u3001\u67d3\u8272\u4f53\u7684\u989c\u8272\u548c\u5206\u6bb5\u3001p\u503c\u7684\u8f6c\u6362\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u56fe\u5f62\u5927\u5c0f<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528Matplotlib\u7684<code>figure<\/code>\u51fd\u6570\u8bbe\u7f6e\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(12, 6))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u67d3\u8272\u4f53\u989c\u8272<\/strong>\uff1a\u901a\u5e38\u901a\u8fc7\u4ea4\u66ff\u989c\u8272\u6765\u533a\u5206\u4e0d\u540c\u67d3\u8272\u4f53\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">colors = [&#39;b&#39;, &#39;g&#39;, &#39;r&#39;, &#39;c&#39;, &#39;m&#39;, &#39;y&#39;, &#39;k&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>p\u503c\u8f6c\u6362<\/strong>\uff1a\u66fc\u54c8\u987f\u56fe\u901a\u5e38\u4f7f\u7528-log10(p\u503c)\u6765\u663e\u793a\u6570\u636e\uff0c\u4ee5\u4fbf\u66f4\u6e05\u6670\u5730\u8bc6\u522b\u663e\u8457\u6027\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">data[&#39;-log10(pvalue)&#39;] = -np.log10(data[&#39;pvalue&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u7ed8\u5236\u56fe\u5f62<\/strong><\/h2>\n<p><p>\u5728\u8bbe\u7f6e\u597d\u53c2\u6570\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u4e86\u3002\u9700\u8981\u901a\u8fc7\u904d\u5386\u67d3\u8272\u4f53\u6570\u636e\uff0c\u5206\u522b\u7ed8\u5236\u6bcf\u4e2a\u67d3\u8272\u4f53\u7684\u70b9\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u67d3\u8272\u4f53\u5206\u6bb5\u7ed8\u5236<\/strong>\uff1a\u4f7f\u7528Matplotlib\u7684<code>scatter<\/code>\u51fd\u6570\u6765\u7ed8\u5236\u6bcf\u4e2a\u67d3\u8272\u4f53\u7684\u6570\u636e\u70b9\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">for i, (chrom, group) in enumerate(data.groupby(&#39;chromosome&#39;)):<\/p>\n<p>    plt.scatter(group[&#39;position&#39;], group[&#39;-log10(pvalue)&#39;], c=colors[i % len(colors)], s=2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6dfb\u52a0\u9608\u503c\u7ebf<\/strong>\uff1a\u901a\u5e38\u5728\u66fc\u54c8\u987f\u56fe\u4e2d\u6dfb\u52a0\u4e00\u6761\u663e\u8457\u6027\u9608\u503c\u7ebf\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">plt.axhline(y=-np.log10(5e-8), color=&#39;r&#39;, linestyle=&#39;--&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001\u4f18\u5316\u53ef\u89c6\u5316\u6548\u679c<\/strong><\/h2>\n<p><p>\u4e3a\u4e86\u4f7f\u66fc\u54c8\u987f\u56fe\u66f4\u52a0\u6e05\u6670\u548c\u6613\u4e8e\u89e3\u8bfb\uff0c\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u4f18\u5316\uff0c\u5982\u8bbe\u7f6e\u8f74\u6807\u7b7e\u3001\u6807\u9898\u3001\u56fe\u4f8b\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e\u8f74\u6807\u7b7e\u548c\u6807\u9898<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">plt.xlabel(&#39;Genomic Position&#39;)<\/p>\n<p>plt.ylabel(&#39;-log10(p-value)&#39;)<\/p>\n<p>plt.title(&#39;Manhattan Plot&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\n<p><strong>\u8c03\u6574\u56fe\u4f8b\u548c\u67d3\u8272\u4f53\u6807\u8bc6<\/strong>\uff1a\u53ef\u4ee5\u5728\u56fe\u4e2d\u6807\u8bc6\u51fa\u4e0d\u540c\u67d3\u8272\u4f53\u7684\u4f4d\u7f6e\uff0c\u4ee5\u4fbf\u4e8e\u533a\u5206\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u548c\u5c55\u793a\u56fe\u5f62<\/strong>\uff1a\u4f7f\u7528Matplotlib\u7684<code>savefig<\/code>\u51fd\u6570\u4fdd\u5b58\u56fe\u5f62\uff0c\u6216\u4f7f\u7528<code>show<\/code>\u51fd\u6570\u76f4\u63a5\u5c55\u793a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">plt.savefig(&#39;manhattan_plot.png&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Python\u7ed8\u5236\u4e00\u4e2a\u57fa\u7840\u7684\u66fc\u54c8\u987f\u56fe\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u56fe\u5f62\u7684\u7f8e\u89c2\u5ea6\u548c\u529f\u80fd\u6027\uff0c\u4f8b\u5982\u6dfb\u52a0\u4ea4\u4e92\u529f\u80fd\u3001\u6ce8\u91ca\u663e\u8457\u533a\u57df\u7b49\u3002\u9009\u62e9\u5408\u9002\u7684\u7ed8\u56fe\u5e93\u548c\u53c2\u6570\u8bbe\u7f6e\u662f\u5173\u952e\u6240\u5728\uff0c\u7ed3\u5408\u5177\u4f53\u7684\u6570\u636e\u548c\u9700\u6c42\u8fdb\u884c\u8c03\u6574\uff0c\u53ef\u4ee5\u5f97\u5230\u66f4\u597d\u7684\u53ef\u89c6\u5316\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\uff1f<\/strong><br \/>\u8981\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684Matplotlib\u548cPandas\u5e93\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5b89\u88c5\u4e86\u8fd9\u4e24\u4e2a\u5e93\u3002\u63a5\u7740\uff0c\u51c6\u5907\u60a8\u7684\u6570\u636e\uff0c\u901a\u5e38\u5305\u62ecSNP\u4f4d\u7f6e\u548c\u5bf9\u5e94\u7684p\u503c\u3002\u4f7f\u7528Matplotlib\u7684scatter\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5730\u7ed8\u5236\u8fd9\u4e9b\u70b9\uff0c\u786e\u4fdd\u5728y\u8f74\u4e0a\u8fdb\u884c-log10\u53d8\u6362\uff0c\u4ee5\u7a81\u51fa\u663e\u793a\u663e\u8457\u6027\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u9700\u8981\u54ea\u4e9b\u6570\u636e\uff1f<\/strong><br \/>\u7ed8\u5236\u66fc\u54c8\u987f\u56fe\u6240\u9700\u7684\u6570\u636e\u4e3b\u8981\u5305\u62ec\u57fa\u56e0\u7ec4\u4f4d\u7f6e\uff08\u901a\u5e38\u662fSNP\u7684\u67d3\u8272\u4f53\u548c\u4f4d\u7f6e\uff09\u548c\u6bcf\u4e2a\u4f4d\u7f6e\u7684p\u503c\u3002\u786e\u4fdd\u60a8\u7684\u6570\u636e\u683c\u5f0f\u6b63\u786e\uff0c\u4f8b\u5982CSV\u6587\u4ef6\uff0c\u5305\u542b\u67d3\u8272\u4f53\u7f16\u53f7\u3001\u4f4d\u7f6e\u548cp\u503c\u4e09\u5217\u3002\u6570\u636e\u7684\u6e05\u6d17\u548c\u9884\u5904\u7406\u4e5f\u5f88\u91cd\u8981\uff0c\u4ee5\u4fbf\u66f4\u51c6\u786e\u5730\u53cd\u6620\u7ed3\u679c\u3002<\/p>\n<p><strong>\u5982\u4f55\u81ea\u5b9a\u4e49\u66fc\u54c8\u987f\u56fe\u7684\u5916\u89c2\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u901a\u8fc7Matplotlib\u7684\u5404\u79cd\u53c2\u6570\u6765\u81ea\u5b9a\u4e49\u66fc\u54c8\u987f\u56fe\u7684\u5916\u89c2\u3002\u8fd9\u5305\u62ec\u8bbe\u7f6e\u56fe\u8868\u6807\u9898\u3001\u8f74\u6807\u7b7e\u3001\u5b57\u4f53\u5927\u5c0f\u3001\u70b9\u7684\u989c\u8272\u548c\u5927\u5c0f\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528<code>plt.title()<\/code>\u3001<code>plt.xlabel()<\/code>\u3001<code>plt.ylabel()<\/code>\u7b49\u51fd\u6570\u6765\u8c03\u6574\u6587\u672c\u5c5e\u6027\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>plt.axhline()<\/code>\u53ef\u4ee5\u6dfb\u52a0\u6c34\u5e73\u7ebf\uff0c\u5e2e\u52a9\u6307\u51fa\u663e\u8457\u6027\u9608\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u753b\u66fc\u54c8\u987f\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u7ed8\u56fe\u5e93\u3001\u51c6\u5907\u6570\u636e\u3001\u8bbe\u7f6e\u56fe\u5f62\u53c2\u6570\u3001\u7ed8\u5236\u56fe\u5f62\u3001\u4f18\u5316\u53ef\u89c6\u5316\u6548\u679c\u3002\u672c\u6587 [&hellip;]","protected":false},"author":3,"featured_media":1014390,"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\/1014377"}],"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=1014377"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1014377\/revisions"}],"predecessor-version":[{"id":1014391,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1014377\/revisions\/1014391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1014390"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1014377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1014377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1014377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}