0

I am trying to store x,y,z points in a database based on conditions. These conditions come from the NACL structure. For example when x is even and y and z are odd, there is an NA atom - that coordinate will be stored as an NA atom. So when I search for where all the NA atoms are, I get a list of coordinates. Another thread asks a similar question where the answer is based around using np.where, but I'm not sure how to implement that in this.

My attempt is in the following code:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

#dimension/shape of grid and array
n = int (input("Enter CUBE dimension: "))

def cube(ax, n):
    #Creating Arrays
    parameter = np.arange(0,n,1)
    xx, yy, zz = np.meshgrid(parameter, parameter, parameter)
    valuesrange = np.zeros((n,n,n))
    #list of arrays
    a = [(xx,yy,zz)]
    # my attempt at the problem
    #    if xx % 2 == 0 and yy % 2 != 0 and zz % 2 !=0:
    #        NA = [(xx,yy,zz)]
    #   elif xx % 2 != 0 and yy % 2 != 0 and zz % 2 ==0:
    #       NA = [(xx,yy,zz)]
    #  Etc...

    print (a)
    scatterplot = ax.scatter(xx, yy, zz, c = valuesrange, cmap=plt.cm.spectral_r, vmin=0, vmax=1,edgecolor = 'black', alpha = .7)    
    return scatterplot


fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

scatterplot1 = cube(ax,n)
plt.colorbar(scatterplot1)
plt.show()

Any help is greatly appreciated!

3
  • 1
    I'm confused. Are you intending to call this function for each point entered? Keep in mind that variables inside functions are LOCAL to the function and will not be available outside of it. Also, I think your indentation is off and it's throwing me, readability-wise. Commented Jun 30, 2017 at 13:59
  • @mauve The coordinates will be categorized and stored. For now, I think they can remain local as the function only needs to run once. I fixed the indentation.Thanks. Commented Jun 30, 2017 at 14:08
  • @P. Camilleri Re copy and pasted code. Hope it's fixed. Commented Jun 30, 2017 at 14:31

1 Answer 1

0

I think adding this to your code will help clarify:

def cube(ax, n):
# Creating Arrays
    parameter = np.arange(0, n, 1)
    xx, yy, zz = np.meshgrid(parameter, parameter, parameter)
    for coordx in range(n):
        for coordy in range(n):
            for coordz in range(n):
                print('xx')
                print(xx[coordx, coordy, coordz])
                print('yy')
                print(yy[coordx, coordy, coordz])
                print('zz')
                print(zz[coordx, coordy, coordz])
    return  

I think what you're missing is that xx isn't a value, it's a matrix of values. You're going to need to compare the values at each position in the matrix to each other. Here's a link about iterating over NumPy Arrays

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.