-1

so there is a big trouble in my script : I have done an array with numpy with contains x,y and z coordinates of some points. some of these points have negative coordinates (for x and/or y and/or z). And for reasons I don't understand, when I use the function scatter from matplotlib, it plots all points with positives coordinates (it means that if a coordinate is negative, it will be plotted as positive...):

enter image description here

So my question is simple : why does it do that, and how to plot points with negatives coordinates properly ?

Here is my code in 2 parts :

#!/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()

here is the second part of the code in an other 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

Here I put an example of the content of the File red by the function 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

Here I put what should show the program :

Cheers !

Eric
  • 95,302
  • 53
  • 242
  • 374
Yoann Pageaud
  • 412
  • 5
  • 22

2 Answers2

1

I'm reading your problem as:

Why do the circles at negative coordinates on the axis into and out of the page look the same as their absolute value

I think your problem is in this line:

self.subplota.scatter(
    self.matrice[:,1],
    self.matrice[:,2],
    c=self.matrice[:,0],
    s=self.matrice[:,0]*100
)

Remember that s is the size in pixels. It's not any kind of 3D support. A circle with radius -100 looks very much the same as a circle with radius 100. You should find the min and max of your data, then pick the circle size based on that.


Have you considered using mplot3d, and just using a pre-built 3d plot window?

Eric
  • 95,302
  • 53
  • 242
  • 374
0

Sorry since I put this message I try run again my scripts and for reasons I still don't get it works ! And the capture I put at the beginning of my message is the good one. I think maybe it's a problem of reloading new datas in python, Maybe I should have restart a session to get those things right... So, If anybody have the same problem I would advise to restart your python session (maybe restart your computer also). This is what I have done, and it works for me. Scripts here are free to use, just be nice and put a little note in your README or in your sources to say that they are from me (Yoann PAGEAUD) ;) ! Thank you all! Cheers!

Yoann Pageaud
  • 412
  • 5
  • 22