Plotting y, z for certain x

Viewed 63

I have a graph of (x, y, z) and would like to make another graph of (y, z) for a few of the x-values, e.g. the (y, z) graph for x=40. The code I have done so far is below:

import numpy as np
from astropy.modeling import models
import matplotlib.pyplot as plt

z = np.zeros((100, 100))
y, x = np.mgrid[0:100, 0:100]
for _ in range(10):
    g2d = models.Gaussian2D(amplitude=100, 
                           x_mean=np.random.randint(0, 100), 
                           y_mean=np.random.randint(0, 100), 
                           x_stddev=3, 
                           y_stddev=3)
    z += g2d(x, y)
    a2d = models.AiryDisk2D(amplitude=70, 
                            x_0=np.random.randint(0, 100), 
                            y_0=np.random.randint(0, 100), 
                            radius=5)
    z += a2d(x, y)

plt.imshow(z)
plt.colorbar().set_label('z Height (nm)', rotation = 270)
plt.xlabel('x Position (nm)')
plt.ylabel('y Position (nm)')
plt.title('AFM Image')
plt.show()

plt.plot(y, z)
plt.title('AFM Line Profile')
plt.xlabel('Position (nm)')
plt.ylabel('Height (nm)')
plt.show()

Topographic Image:

image 2

Line Profile:

image 3

(I want to separate the multiple lines in this graph into their own plots)

1 Answers

I don't have astropy so I can't test this but try this in the last code block:

plt.plot(y[x == 40], z[x == 40])
Related