Skip to content

Commit

Permalink
pybamm-team#1051 fix 2D plot bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Jun 14, 2020
1 parent 06237e9 commit fb88e8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Unreleased

## Features

## Optimizations

## Bug fixes

- Fix a bug where variables that depend on y and z were transposed in `QuickPlot` ([]())

## Breaking changes

# [v0.2.2](https://github.com/pybamm-team/PyBaMM/tree/v0.2.2) - 2020-06-01

New SEI models, simplification of submodel structure, as well as optimisations and general bug fixes.
Expand Down
20 changes: 18 additions & 2 deletions pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def set_output_variables(self, output_variables, solutions):
self.first_spatial_scale = {}
self.second_spatial_scale = {}
self.is_x_r = {}
self.is_y_z = {}

# Calculate subplot positions based on number of variables supplied
self.subplot_positions = {}
Expand Down Expand Up @@ -354,8 +355,15 @@ def set_output_variables(self, output_variables, solutions):
)
if first_spatial_var_name == "r" and second_spatial_var_name == "x":
self.is_x_r[variable_tuple] = True
self.is_y_z[variable_tuple] = False
elif (
first_spatial_var_name == "y" and second_spatial_var_name == "z"
):
self.is_x_r[variable_tuple] = False
self.is_y_z[variable_tuple] = True
else:
self.is_x_r[variable_tuple] = False
self.is_y_z[variable_tuple] = False

# Store variables and subplot position
self.variables[variable_tuple] = variables
Expand Down Expand Up @@ -585,7 +593,11 @@ def plot(self, t):
y_name = list(spatial_vars.keys())[1][0]
x = self.first_dimensional_spatial_variable[key]
y = self.second_dimensional_spatial_variable[key]
var = variable(t_in_seconds, **spatial_vars, warn=False).T
# need to transpose if domain is x-z
if self.is_y_z[key] is True:
var = variable(t_in_seconds, **spatial_vars, warn=False)
else:
var = variable(t_in_seconds, **spatial_vars, warn=False).T
ax.set_xlabel(
"{} [{}]".format(x_name, self.spatial_unit), fontsize=fontsize
)
Expand Down Expand Up @@ -717,7 +729,11 @@ def slider_update(self, t):
else:
x = self.first_dimensional_spatial_variable[key]
y = self.second_dimensional_spatial_variable[key]
var = variable(time_in_seconds, **spatial_vars, warn=False).T
# need to transpose if domain is x-z
if self.is_y_z[key] is True:
var = variable(time_in_seconds, **spatial_vars, warn=False)
else:
var = variable(time_in_seconds, **spatial_vars, warn=False).T
ax.contourf(
x, y, var, levels=100, vmin=vmin, vmax=vmax, cmap="coolwarm"
)
Expand Down

0 comments on commit fb88e8f

Please sign in to comment.