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

Line plot with x=coord putting wrong variables on axes #2725

Closed
TomNicholas opened this issue Jan 29, 2019 · 3 comments
Closed

Line plot with x=coord putting wrong variables on axes #2725

TomNicholas opened this issue Jan 29, 2019 · 3 comments

Comments

@TomNicholas
Copy link
Member

When I try to plot the values in a 1D DataArray against the values in one of its coordinates, it does not behave at all as expected:

import numpy as np
import matplotlib.pyplot as plt
from xarray import DataArray

current = DataArray(name='current', data=np.array([5, 8, 14, 22, 30]), dims=['time'],
                    coords={'time': (['time'], np.array([0.1, 0.2, 0.3, 0.4, 0.5])),
                            'voltage': (['time'], np.array([100, 200, 300, 400, 500]))})

print(current)

# Try to plot current against voltage
current.plot.line(x='voltage')
plt.show()

Output:

<xarray.DataArray 'current' (time: 5)>
array([ 5,  8, 14, 22, 30])
Coordinates:
  * time     (time) float64 0.1 0.2 0.3 0.4 0.5
    voltage  (time) int64 100 200 300 400 500

incorrect_current_plot

Problem description

Not only is 'voltage' not on the x axis, but 'current' isn't on the y axis either!

Expected Output

Based on the documentation (and common sense) I would have expected it to plot voltage on the x axis and current on the y axis.

(using a branch of xarray which is up-to-date with master)

@TomNicholas TomNicholas changed the title Line plot with 'x'=coord putting wrong variables on axes Line plot with x=coord putting wrong variables on axes Jan 29, 2019
@TomNicholas
Copy link
Member Author

TomNicholas commented Jan 29, 2019

@dcherian I guess this is an issue somewhere in #1926?

@dcherian
Copy link
Contributor

dcherian commented Jan 29, 2019

Thanks @TomNicholas. Here's the diff that gets it working (minus error-checking & tests). I can't get to it until tonight so if you have the time to go ahead and send in a PR, please do so.

EDIT: This needs to account for x is None, y is None.

image

@TomNicholas
Copy link
Member Author

TomNicholas commented Jan 29, 2019

Thanks @dcherian !

Fixed, including tests, in #2726 .

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

No branches or pull requests

2 participants