Skip to content
Snippets Groups Projects
Commit a020231a authored by Daniel Brown's avatar Daniel Brown
Browse files

2d plotting examples, probably want to wrap these plots up in a function to...

2d plotting examples, probably want to wrap these plots up in a function to make it easier in future. Fixed ordering of output rows/cols in the stored matrix for 2d outputs.
parent 044af4a9
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ from pykat.detectors import * ...@@ -4,6 +4,7 @@ from pykat.detectors import *
from pykat.components import * from pykat.components import *
from pykat.commands import * from pykat.commands import *
from pykat.structs import * from pykat.structs import *
import matplotlib.image as mpimg
from mpl_toolkits.mplot3d.axes3d import Axes3D from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np import numpy as np
...@@ -13,11 +14,12 @@ code = """ ...@@ -13,11 +14,12 @@ code = """
l l1 1 0 0 n1 l l1 1 0 0 n1
s s1 10 1 n1 n2 s s1 10 1 n1 n2
ad ad1 0 n2
beam b1 0 n2 beam b1 0 n2
maxtem 0 maxtem 0
xaxis b1 x lin -7.0 7.0 50 xaxis b1 x lin -10.0 10 100
x2axis b1 y lin -7.0 7.0 50 x2axis b1 y lin -6 6 100
""" """
...@@ -31,5 +33,17 @@ out = kat.run(printout=0,printerr=0) ...@@ -31,5 +33,17 @@ out = kat.run(printout=0,printerr=0)
fig = pl.figure() fig = pl.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d') ax = fig.add_subplot(1, 1, 1, projection='3d')
x, y = np.meshgrid(out.x, out.y) x, y = np.meshgrid(out.x, out.y)
p = ax.plot_surface(x, y, out.z[0,:]) p = ax.plot_wireframe(x, y, out.z[1])
pl.xlabel(out.xlabel)
pl.ylabel(out.ylabel)
pl.show()
pl.figure()
extent = [np.min(out.x),np.max(out.x),np.min(out.y),np.max(out.y)]
imgplot = pl.imshow(out.z[1], extent=extent)
#imgplot.set_interpolation('bicubic')
imgplot.set_interpolation('nearest')
pl.colorbar()
pl.xlabel(out.xlabel)
pl.ylabel(out.ylabel)
pl.show() pl.show()
...@@ -524,8 +524,11 @@ class kat(object): ...@@ -524,8 +524,11 @@ class kat(object):
# written in linear form # written in linear form
x = data[0::(1+self.x2axis.steps),0] x = data[0::(1+self.x2axis.steps),0]
y = data[0:(1+self.x2axis.steps),1] y = data[0:(1+self.x2axis.steps),1]
# get rows and columns lined up so that we can reshape a single column of all x/y data
# into a matrix
z = data[:,2:].transpose().reshape(data.shape[1]-2, 1+self.xaxis.steps, 1+self.x2axis.steps) z = data[:,2:].transpose().reshape(data.shape[1]-2, 1+self.xaxis.steps, 1+self.x2axis.steps)
# once you do this the data for y and x axes need swapping
z = z.swapaxes(1,2)
return [x, y, z, hdr] return [x, y, z, hdr]
else: else:
shape_len = len(data.shape) shape_len = len(data.shape)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment