Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

How do I make a custom path using python and matplotlib?

For my study project, I need to write an algorithm that tries to find the best solution to fold a protein. In order to make interpretation easy I wat to make a visualisation using MatPlotLib, exactly like this: enter image description here

I followed some examples on the internet and managed to come up with the following code:`

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt

protein = "PHPPHPHH"
coordinates = [(0, 0), (0, 1), (-1, 1), (-1, 2), (0, 2), (1, 2), (1, 1), (1, 0)]

fig, ax = plt.subplots()
Path = mpath.Path
path_data = []



for i in range(len(coordinates)):
    if i == 0:
        path_data.append((Path.MOVETO, (coordinates[i])))
    else:
        path_data.append((Path.LINETO, (coordinates[i])))
print(path_data)


codes, verts = zip(*path_data)
path = mpath.Path(verts, codes)

# plot control points and connecting lines
x, y = zip(*path.vertices)
line, = ax.plot(x, y, 'go-', color='grey')


ax.grid()
ax.axis('equal')
plt.title('Visualisation')
plt.legend()
plt.savefig("Visualisation.png")`

Resulting in this visualisation: enter image description here

My question is: -How can I change the color of the dots corresponding to the amino acids(H or P) and add a corresponding legend?

  • How do I draw the dotted lines in the case that two H amino acids lay next to eachother and can bond?

Thank you in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...