comparison EquidistantGrid.jl @ 53:8c6db1f6d8e0

Save plot to file when calling plotgridfunction, until figuring out how to set up an interactive gui backend for matplotlib in julia.
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Mon, 14 Jan 2019 11:30:36 +0100
parents 614b56a017b9
children f3ea15c8ebb6 a94ebe67e848
comparison
equal deleted inserted replaced
52:0236f8e90567 53:8c6db1f6d8e0
94 @assert dim>0 94 @assert dim>0
95 points = range(grid.limits[1][dim],stop=grid.limits[2][dim],length=grid.numberOfPointsPerDim[dim]) 95 points = range(grid.limits[1][dim],stop=grid.limits[2][dim],length=grid.numberOfPointsPerDim[dim])
96 end 96 end
97 97
98 using PyPlot, PyCall 98 using PyPlot, PyCall
99 # using Plots; pyplot() 99 #pygui(:qt)
100 #using Plots; pyplot()
100 101
101 function plotgridfunction(grid::EquidistantGrid, gridfunction) 102 function plotgridfunction(grid::EquidistantGrid, gridfunction)
102 if numberOfDimensions(grid) == 1 103 if numberOfDimensions(grid) == 1
103 plot(pointsalongdim(grid,1), gridfunction, linewidth=2.0) 104 plot(pointsalongdim(grid,1), gridfunction, linewidth=2.0)
104 elseif numberOfDimensions(grid) == 2 105 elseif numberOfDimensions(grid) == 2
105 mx = grid.numberOfPointsPerDim[1]; 106 mx = grid.numberOfPointsPerDim[1];
106 my = grid.numberOfPointsPerDim[2]; 107 my = grid.numberOfPointsPerDim[2];
107 x = pointsalongdim(grid,1) 108 x = pointsalongdim(grid,1)
108 X = repeat(x,1,my) 109 X = repeat(x,1,my)
109 y = pointsalongdim(grid,2) 110 y = pointsalongdim(grid,2)
110 Y = repeat(y,1,mx) 111 Y = permutedims(repeat(y,1,mx))
111 # plot_surface(X,Y,reshape(gridfunction,mx,my)) 112 plot_surface(X,Y,reshape(gridfunction,mx,my))
112 fig = figure() 113 # fig = figure()
113 ax = fig[:add_subplot](1,1,1, projection = "3d") 114 # ax = fig[:add_subplot](1,1,1, projection = "3d")
114 ax[:plot_surface](X,Y,reshape(gridfunction,mx,my)) 115 # ax[:plot_surface](X,Y,reshape(gridfunction,mx,my))
115 plt[:show]()
116 else 116 else
117 error(string("Plot not implemented for dimension ", string(numberOfDimensions(grid)))) 117 error(string("Plot not implemented for dimension ", string(numberOfDimensions(grid))))
118 end 118 end
119 savefig("gridfunction")
119 end 120 end