Skip to content
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

Issue 992 plot arrays #1008

Merged
merged 6 commits into from
May 26, 2020
Merged

Issue 992 plot arrays #1008

merged 6 commits into from
May 26, 2020

Conversation

rtimms
Copy link
Contributor

@rtimms rtimms commented May 20, 2020

Description

Added basic plots for 1D and 2D arrays (pybamm.plot and pybamm.plot2D). I've left these as separate methods, but I guess they could be combined and the appropriate plot called depending on what arrays you pass. On the other hand, maybe it is better to be explicit.

Also added pybamm.linspace and pybamm.meshgrid to quickly create some common arrays.

Fixes #992

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rtimms , some comments

@@ -223,7 +223,7 @@ def version(formatted=False):
#
# other
#
from .quick_plot import QuickPlot, dynamic_plot, ax_min, ax_max
from .quick_plot import QuickPlot, plot, plot2D, dynamic_plot, ax_min, ax_max
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth making a new plotting folder with a few different functions in different files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

y = pybamm.Array(np.array([6, 16, 78]))
X, Y = pybamm.meshgrid(x, y)

pybamm.plot2D(X, Y, Y, xlabel="x", ylabel="y", title="title", testing=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could plot2D automatically do meshgrid(x,y) if they aren't given in meshgrid form?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out contourf handles this provided they are the correct shape. have added some lines to account for this



def linspace(start, stop, num=50, **kwargs):
"Creates a linearly spaced array"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pick out num from the kwargs? Also, link to np.linspace docs for the kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this so you can do pybamm.linspace(0,1,100) without needing to do num=100 as I think it's a pretty common use case and you can just do np.linspace(0,1,100) directly. that didn't work unless I picked out num but maybe there is a better/more common solution?



def meshgrid(x, y, **kwargs):
"Return coordinate matrices as from coordinate vectors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link np.meshgrid docs for the kwargs

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks

@rtimms rtimms merged commit cfd982d into develop May 26, 2020
@valentinsulzer valentinsulzer deleted the issue-992-plot-arrays branch May 27, 2020 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plot pybamm arrays
2 participants