-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot parameter functions #1465
Comments
This is actually listed as one of the bullet points in #1458 . @Saransh-cpp , just some thoughts here on plotting parameters |
I'll have a look and see if I can implement the |
Just a comment - when we provide custom plotting functions we need to be careful not to do so at the expense of matplotlib flexibility (specifying args and kwargs in the plot, adding xlabel and ylabel and legend, etc). |
Good point re plotting. Maybe instead of adding extra plotting functionality, we could add something that makes it easier to get a callable function from E.g. you can do import pybamm
def myfun(x):
return pybamm.Parameter("D") * x
params = pybamm.ParameterValues({"D":2, "function":myfun})
def f(x):
return params.process_symbol(params["function"](x))
x = pybamm.linspace(0,1,10)
pybamm.plot(x,f(x)) It would be handy to get It's not a huge effort to define PS I know this is a stupid example as you could just call |
This simple function does work but is, as it looks, limited to the above example (should be modified to add all plots in a single screen though). Should we generalize this or will it be better to just create a function for returning def plot(self, values, eval):
self.check_parameter_values(values)
for value in values:
processed = self.process_symbol(self[value](eval[0], eval[1], eval[2]))
pybamm.plot(eval[1], processed, xlabel="time", ylabel=value) Driver code being import pybamm
params = pybamm.ParameterValues(chemistry=pybamm.parameter_sets.Chen2020)
x = pybamm.linspace(3000,6000,100)
params.plot(values=["Negative electrode exchange-current density [A.m-2]"], eval=(1000, x, 300)) |
Yeah, I think maybe it is better to just create a function that returns the processed parameter function. Each of the parameter functions may have a different number of arguments, and maybe trying to be clever with the plotting will get out of hand. Then thoughts @tinosulzer ? |
Doesn't
agreed |
Almost, but it returns an expression tree rather than an array. If the function itself contains a Soemthing like def process_function(name):
function_parameter = params[name]
def function(*args):
return params.process_symbol(function_parameter(*args))
return function but defined as a method of g = process_function("Negative electrode exchange-current density [A.m-2]")
pybamm.plot(x,g(1000,x,300)) |
I see the issue now. What about editing the |
…n-parameters #1465 allow evaluate parameter to return arrays
Some parameters are provided as functions (e.g. diffusivity as a function of concentration and temperature). Currently, to plot them you have to do something like this
We have to process the function "Negative electrode exchange-current density [A.m-2]" since its definition contains a
pybamm.Parameter
. It would be neat to be able to do something likeparams.plot("Negative electrode exchange-current density [A.m-2]", (1000, x, 300))
instead so you can quickly plot the functional dependence of parameters. We can usepybamm.plot
andpybamm.plot2D
to plot the resulting arrays.Maybe you could pass a list or dict of parameter names and values so you can plot multiple parameters on the same plot.
The text was updated successfully, but these errors were encountered: