Python和Matplotlib:字符作为x轴

嗨Stack Overflow社区.我想我正在尝试用matplotlib编写不可能的代码,所以如果有一个不同的 python库会更适合我,请告诉我!

我有一个蛋白质(蛋白质x)的完整氨基酸序列(在图像中表示为大写字母).这将是我的x轴.

我有两个excel专栏:疾病和控制.这些列包含整个蛋白质x氨基酸序列的部分.有时会有多次命中,其中疾病或对照柱将包含两个相同的蛋白x氨基酸部分.我希望这些能够叠加在一起,以便人们可以看到疾病和对照对蛋白质x有多少命中.

混乱?对不起,这是我使用powerpoint想出的一个示例.

氨基酸比较

黑色文本是参考序列.紫色是控制.粉红色是疾病.现在有道理吗?

我需要使用一个巨大的数据集,所以不,我不想“只使用powerpoint几个小时”.我也想用我选择的任何参考序列来做.

我不是要求别人为我做我的工作.我需要有人指出我正确的方向.有专门的图书馆吗?我应该将所有内容转换为数字然后重新标记为文本吗?

谢谢,我感谢任何建议.

最佳答案 使用脚本创建SVG图像,这是一个 XML文本.我会解决一些更简单的问题!

假设你的目标就是这个.
《Python和Matplotlib:字符作为x轴》

首先打破每个地方的大字符串,在那里会有一列字符串片段,在这种情况下,在’EF’和’IJKL’.您可以使用SVG XML的功能(目前更多)来定位大字符串的片段.由于您知道片段的起始位置和字符的高度,因此您可以在列中定位图层.

这是你必须建立的那种东西.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg8"
   inkscape:version="0.92.0 r15299"
   sodipodi:docname="genes.svg">
  <defs
     id="defs2" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="1.4"
     inkscape:cx="170.60599"
     inkscape:cy="341.08014"
     inkscape:document-units="mm"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1095"
     inkscape:window-height="676"
     inkscape:window-x="145"
     inkscape:window-y="122"
     inkscape:window-maximized="0" />
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1">
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Courier;-inkscape-font-specification:Courier;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
       x="24.588797"
       y="179.4014"
       id="text12"><tspan
         sodipodi:role="line"
         id="tspan10"
         x="24.588797"
         y="185.32886"
         style="stroke-width:0.26458332;-inkscape-font-specification:Courier;font-family:Courier;font-weight:normal;font-style:normal;font-stretch:normal;font-variant:normal;" /></text>
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
       x="23.8125"
       y="207.41963"
       id="text24"><tspan
         sodipodi:role="line"
         id="tspan22"
         x="23.8125"
         y="207.41963"
         style="stroke-width:0.26458332">ABCD</tspan></text>
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
       x="46.302082"
       y="207.41965"
       id="text28"><tspan
         sodipodi:role="line"
         id="tspan26"
         x="46.302082"
         y="207.41963"
         style="stroke-width:0.26458332">EFGH</tspan></text>
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
       x="67.657738"
       y="207.41963"
       id="text32"><tspan
         sodipodi:role="line"
         id="tspan30"
         x="67.657738"
         y="207.41963"
         style="stroke-width:0.26458332">IJKLMN</tspan></text>
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
       x="46.680061"
       y="199.67113"
       id="text36"><tspan
         sodipodi:role="line"
         id="tspan34"
         x="46.302082"
         y="199.67113"
         style="stroke-width:0.26458332">EF</tspan></text>
    <text
       xml:space="preserve"
       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.8777771px;line-height:6.61458302px;font-family:Calibri;-inkscape-font-specification:'Calibri, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
       x="67.846725"
       y="192.86755"
       id="text40"><tspan
         sodipodi:role="line"
         id="tspan38"
         x="67.657738"
         y="192.86755"
         style="stroke-width:0.26458332">IJKL</tspan></text>
  </g>
</svg>

显然我已经在Inkscape中完成了它,但你会明白的.这里没有任何东西在Python中无法完成

点赞