Yes, sorry about that. I hope this now works.
Tanim Islam
On Mon, 30 Apr 2012, Benjamin Root wrote:
On Mon, Apr 30, 2012 at 2:02 PM, Tanim Islam <tanim.is...@gmail.com> wrote:
Apologies, but attached to this email are the 2 python scripts I have
neglected to attach to the previous email.
Tanim Islam
Tanim,
Could you try that again? No python scripts came with that email.
Ben Root
#!/usr/bin/env python -i
import pylab, numpy, inspect
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import FuncFormatter
def scinot(x, pos=None):
if x == 0:
s = '0'
else:
xp = int(numpy.floor(numpy.log10(numpy.abs(x))))
mn = x/10.**xp
# Here we truncate to 2 significant digits -- may not be enough
# in all cases
s = '$'+str('%.1f'%mn) +'\\times 10^{'+str(xp)+'}$'
return s
pylab.close()
u = numpy.random.random_sample(300)
v = numpy.random.random_sample(300)
w = numpy.random.random_sample(300)
mag = numpy.sqrt(u**2 + v**2 + w**2)
## fundamentally nontrivial things to customize a colorbar to look nice
## in pylab/matplotlib
fig = pylab.figure(figsize=(15,13.5)) # make the figure bigger
axes3d = Axes3D(fig)
patches = axes3d.scatter(u, v, w, c=mag, cmap=cm.jet,
vmin=0.5, vmax=1.5, s=30.5)
cb = fig.colorbar(patches, shrink=0.75, aspect=20, pad=0.05,
orientation='vertical', fraction=0.10,
format=FuncFormatter(scinot))
#cb.ax.set_major_formatter(FuncFormatter(scinot))
pylab.show()
#!/usr/bin/env python -i
import pylab, numpy, os
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import FuncFormatter
def create_colors(vals, minval, maxval):
gradients = cm.jet(numpy.linspace(0, 1.0, 101))
normvals = (numpy.array(vals) - minval) / (maxval - minval)
rgbacolors = numpy.zeros((len(vals), 4))
for idx in range(len(vals)):
actidx = max(0, min(100, int(normvals[idx] * 100)))
rgbacolors[idx,:] = gradients[actidx]
return rgbacolors
def scinot(x, pos=None):
if x == 0:
s = '0'
else:
xp = int(numpy.floor(numpy.log10(numpy.abs(x))))
mn = x/10.**xp
# Here we truncate to 2 significant digits -- may not be enough
# in all cases
s = '$'+str('%.1f'%mn) +'\\times 10^{'+str(xp)+'}$'
return s
pylab.close()
xd = []
yd = []
zd = []
vmag_d = []
for line in open(os.path.expanduser('~/temp/data_output.txt'), 'r'):
linesplit = line.strip().split()
xd.append(float(linesplit[0]))
yd.append(float(linesplit[1]))
zd.append(float(linesplit[2]))
vmag_d.append(float(linesplit[3]))
xd_min = min(xd)
xd_max = max(xd)
yd_min = min(yd)
yd_max = max(yd)
zd_min = min(zd)
zd_max = max(zd)
fig = pylab.figure(figsize=(15,13.5))
axes3d = Axes3D(fig)
scatter = axes3d.scatter(numpy.array(xd), numpy.array(yd),
numpy.array(zd),
c = numpy.array(vmag_d),
cmap = cm.jet,
s = 1.0)
axes3d.set_xlim3d([xd_min, xd_max])
axes3d.set_ylim3d([yd_min, yd_max])
axes3d.set_zlim3d([zd_min, zd_max])
axes3d.set_xlabel(r'$x$ (cm)')
axes3d.set_ylabel(r'$y$ (cm)')
axes3d.set_zlabel(r'$z$ (cm)')
axes3d.w_xaxis.set_major_formatter(FuncFormatter(scinot))
axes3d.w_yaxis.set_major_formatter(FuncFormatter(scinot))
axes3d.w_zaxis.set_major_formatter(FuncFormatter(scinot))
fig.colorbar(scatter, orientation='vertical', shrink=0.75, aspect=20, pad=0.05,
fraction=0.10, format=FuncFormatter(scinot))
pylab.show()
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users