On Monday, June 4, 2012 9:13:03 PM UTC-4, Jason Grout wrote: > > On 6/4/12 7:15 PM, Dan Aldrich wrote: > > Well, I spoke too soon. I can plot the matrix, but not contour_plot it. > > > > V = matrix([ > > [0.020, 0.020, 0.016, 0.014, 0.011, 0.011], > > [0.021, 0.018, 0.016, 0.013, 0.010, 0.011], > > [0.017, 0.015, 0.015, 0.012, 0.010, 0.011], > > [0.013, 0.013, 0.011, 0.009, 0.007, 0.009], > > [0.011, 0.010, 0.009, 0.007, 0.005, 0.007], > > [0.010, 0.009, 0.009, 0.007, 0.005, 0.007] > > ]) > > #contour_plot(V,(0,1),(0,1)) > > plot(V) > > There are several things you could do: > > Use the matplotlib contour functions directly, which do take matrices. > > Define a function which returns the matrix value, given an x and y > > Use interpolation to make the last point a little smarter. > > Here's an example where I use scipy to interpolate values: > > V = matrix([ > [0.020, 0.020, 0.016, 0.014, 0.011, 0.011], > [0.021, 0.018, 0.016, 0.013, 0.010, 0.011], > [0.017, 0.015, 0.015, 0.012, 0.010, 0.011], > [0.013, 0.013, 0.011, 0.009, 0.007, 0.009], > [0.011, 0.010, 0.009, 0.007, 0.005, 0.007], > [0.010, 0.009, 0.009, 0.007, 0.005, 0.007] > ]) > > from scipy.interpolate import interp2d > g=interp2d(range(V.nrows()), range(V.ncols()), V.numpy()) > def f(x,y): > return g(x,y)[0] > contour_plot(f,(0,V.nrows()), (0,V.ncols()),plot_points=100, > colorbar=True) > > See http://aleph.sagemath.org/?q=99e63821-cafa-423f-ae8e-d94174a62a87 >
Cool. Is this a "standard" enough thing to take discrete data and get a contour plot that we should wrap this (perhaps overloading contour_plot)? -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org