Hello, I am trying to fix up some plots based on Colin's Camassa-Holm demo. http://firedrakeproject.org/demos/camassaholm.py.html I have two questions on plotting. 1. How do we set the y-limits in the context of the plot function? In matplotlib I would do ylim([0,1]) for example but that doesn't seem to work in this context. 2. If I wanted to make a Hovmoeller plot instead of a move I would like to be able to store the snapshots into an array and then plot those. Does someone have a suggestion on how one can do this easily? Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637
On 20/04/17 04:39, Francis Poulin wrote:
Hello,
I am trying to fix up some plots based on Colin's Camassa-Holm demo.
http://firedrakeproject.org/demos/camassaholm.py.html
I have two questions on plotting.
1. How do we set the y-limits in the context of the plot function? In matplotlib I would do ylim([0,1]) for example but that doesn't seem to work in this context.
you get an Axes object back from plot, so you can do: axes = plot(...) axes.set_ylim(...)
2. If I wanted to make a Hovmoeller plot instead of a move I would like to be able to store the snapshots into an array and then plot those. Does someone have a suggestion on how one can do this easily?
You can evaluate each function in turn using: from firedrake.plot import calculate_one_dim_points xyvals = calculate_one_dim_points(my_function, interpolation_points_per_element) now you'll have to do your own work to glue this together from a bunch of different function evaluations and do a 2D surface plot. The other option is to make an extruded mesh where the number of layers is the number of values you have. Then you take your existing function space and do: element = TensorProductElement(V.ufl_element(), FiniteElement("DG", interval, 0)) W = FunctionSpace(extmesh, element) now you can make a Function on W and store one one-D function per layer, like so: full = Function(W) for i in range(nfunc): full.dat.data[W.cell_node_map().values + i] = oned[i].dat.data_ro[oned[i].cell_node_map().values] Untested. Lawrence
Thank you Lawrence for all the helpful information. Needless to say, that is not at all what I tried. I ended up dumping the functions to numpy arrays and then using matplotlib. Since I know the plotting well, it was much easier for me. But I might try this for fun to see how the methods compare. Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Lawrence Mitchell [lawrence.mitchell@imperial.ac.uk] Sent: Tuesday, April 25, 2017 6:36 AM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] a question on plotting On 20/04/17 04:39, Francis Poulin wrote:
Hello,
I am trying to fix up some plots based on Colin's Camassa-Holm demo.
http://firedrakeproject.org/demos/camassaholm.py.html
I have two questions on plotting.
1. How do we set the y-limits in the context of the plot function? In matplotlib I would do ylim([0,1]) for example but that doesn't seem to work in this context.
you get an Axes object back from plot, so you can do: axes = plot(...) axes.set_ylim(...)
2. If I wanted to make a Hovmoeller plot instead of a move I would like to be able to store the snapshots into an array and then plot those. Does someone have a suggestion on how one can do this easily?
You can evaluate each function in turn using: from firedrake.plot import calculate_one_dim_points xyvals = calculate_one_dim_points(my_function, interpolation_points_per_element) now you'll have to do your own work to glue this together from a bunch of different function evaluations and do a 2D surface plot. The other option is to make an extruded mesh where the number of layers is the number of values you have. Then you take your existing function space and do: element = TensorProductElement(V.ufl_element(), FiniteElement("DG", interval, 0)) W = FunctionSpace(extmesh, element) now you can make a Function on W and store one one-D function per layer, like so: full = Function(W) for i in range(nfunc): full.dat.data[W.cell_node_map().values + i] = oned[i].dat.data_ro[oned[i].cell_node_map().values] Untested. Lawrence
participants (2)
- 
                
                Francis Poulin
- 
                
                Lawrence Mitchell