所以在我的腳本中有一個很大的麻煩:我已經做了一個包含點,包含x,y和z座標的numpy數組。其中一些點具有負座標(對於x和/或y和/或z)。由於我不明白的原因,當我使用matplotlib中的函數scatter時,它繪製了所有具有正座標的點(這意味着如果座標爲負值,它將被繪製爲正值):Python - 爲什麼散佈matplotlib繪製具有負座標,具有正座標的點?
所以我的問題很簡單:它爲什麼這樣做,以及如何繪製與負面座標正確的點?
這裏是我的兩個部分代碼:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Tkinter
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import numpy as np
import os
import subprocess
import Parse_Gro
class windowsTk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.f = Figure(figsize=(6, 6), dpi=100)
self.canevas = FigureCanvasTkAgg(self.f, master=self)
self.subplota= self.f.add_subplot(111)
self.RotateMatY= np.matrix([[np.cos(0.2*np.pi),0,np.sin(0.2*np.pi)],[0,1,0],[-np.sin(0.2*np.pi),0,np.cos(0.2*np.pi)]])
self.RotateMatZ= np.matrix([[np.cos(0.2*np.pi),-np.sin(0.2*np.pi),0],[np.sin(0.2*np.pi),np.cos(0.2*np.pi),0],[0,0,1]])
self.matrice=Parse_Gro.get_Coordinates()
self.initialize()
def initialize(self):
self.grid()
self.canevas.get_tk_widget().grid(column=0,row=0,columnspan=3)
button1 = Tkinter.Button(self,text=u"Rotate Right",command=self.ClickonRight)
button1.grid(column=2,row=2)
button2 = Tkinter.Button(self,text=u"Rotate Left",command=self.ClickonLeft)
button2.grid(column=0,row=2)
button3 = Tkinter.Button(self,text=u"Rotate Up",command=self.ClickonUp)
button3.grid(column=1,row=1)
button4 = Tkinter.Button(self,text=u"Rotate Down",command=self.ClickonDown)
button4.grid(column=1,row=3)
#Sort according to X coordinate (first column)
#self.matrice=np.sort(self.matrice, axis=0)
#Scatter Plot Test
self.subplota.scatter(self.matrice[:,1],self.matrice[:,2],c=self.matrice[:,0],s=self.matrice[:,0]*100)
def ClickonRight(self):
print"Right Rotation"
def ClickonLeft(self):
print"Left Rotation"
def ClickonUp(self):
print"Up Rotation"
def ClickonDown(self):
print"Down Rotation"
if __name__ == "__main__":
app = windowsTk(None)
app.title('Visualisation 3D Proteine')
app.mainloop()
這裏是代碼的在其他file.py
第二部分:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import numpy as np
def get_Coordinates():
path = raw_input("Enter a Path to your PDB file: ")
#Path Example :/home/yoann
os.chdir(path)
filename = raw_input("Enter the name of your PDB file: ")
#Filename Example : 5f4c.pdb
bashCommand = "gmx editconf -f {:s} -o output.gro -center 0 0 0 -aligncenter 0 0 0".format(filename)
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
ListX=[]
ListY=[]
ListZ=[]
with open("/home/yoann/output.gro","r") as file:
lines = file.readlines()
for line in lines[2:-1:]:
ListX.append(float(line[22:28]))
ListY.append(float(line[30:36]))
ListZ.append(float(line[38:44]))
matrixCoord=np.column_stack([ListX,ListY,ListZ])
return matrixCoord
在這裏,我把文件的內容的一個例子紅色由函數get_Coordinate():
PUTATIVE CYTOPLASMIC PROTEIN
1637
1MET N 1 1.206 1.701 1.641
1MET CA 2 1.077 1.663 1.575
2ASN C 11 0.687 1.503 1.675
2ASN O 12 0.688 1.495 1.550
這裏我把什麼應該顯示程序:
乾杯!
你能讓它重現嗎?您的'get_Coordinates'讀取我們無權訪問的文件。將其更改爲返回最小(如果可能)一組數據,這會導致問題。 – DJV
您能否包含圖形的屏幕截圖? – Eric
嗨DJV, 我更新我的問題,以函數Get_coordinate() 乾紅的文件中的行示例! –