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

Fix: Matplot interpolate x and y coords for pcolormesh #615

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions qcodes/plots/qcmatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ def add_to_plot(self, **kwargs):
# in case the user has updated title, don't change it anymore
self.title.set_text(self.get_default_title())

@staticmethod
def _calc_corners(array):
"""
Extrapolate coordinates of between data points from a list of data points.
Needed because pcolor and friends take the list of edges as x and y rather
than the center positions. This should handle general non linear axis.
"""
myarray = array.copy()
# extrapolate points before and after array
# so we can find steps in the end/start
myarray_plusone = 2 * myarray[-1] - myarray[-2]
myarray_minusone = 2 * myarray[0] - myarray[1]
myarray = np.append(myarray, myarray_plusone)
myarray = np.insert(myarray, 0, myarray_minusone)
# find the difference between steps
stepsizes = np.diff(myarray)
# calculate edges
myarray_corners = myarray[0:-1] + stepsizes / 2
return myarray_corners

def _get_axes(self, config):
return self.subplots[config.get('subplot', 1) - 1]

Expand Down Expand Up @@ -218,6 +238,24 @@ def _draw_pcolormesh(self, ax, z, x=None, y=None, subplot=1,
yunit=None,
zunit=None,
**kwargs):

# Polormesh and friends expect coordinates of corners not the center of datapoints
# here we expands the x and y coordinates to match what pcolormesh expects.
# first we verify that the shapes are as expected

# x is the inner most index so it is 2 dimensional.
# however y is outer most so it is 1 dimensional
if x:
assert x.shape == z.shape
new_xshape = np.array(x.shape) + 1
new_x = np.zeros(new_xshape)
for i in range(len(x[:, 0])):
new_x[i] = self._calc_corners(x[i])
new_x[i+1] = new_x[i]
x = new_x
if y:
assert y.shape[0] == z.shape[0] and len(y.shape)==1
y = self._calc_corners(y)
# NOTE(alexj)stripping out subplot because which subplot we're in is already
# described by ax, and it's not a kwarg to matplotlib's ax.plot. But I
# didn't want to strip it out of kwargs earlier because it should stay
Expand Down