pydata / pydata/xarray

DataArray plotting: pyplot compat and passing the style

Open
#2,837 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

contrib-help-wanted topic-plotting
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

These are two unrelated issues in one really that I've noticed while trying to plot things directly from DataArray objects.


The following works as expected, by converting DataArray to pandas first)

>>> arr.to_series().plot(style='.-')
>>> arr.to_series().plot.line(style='.-')

Passing Series to pyplot.plot() directly also works and retains index:

>>> plt.plot(arr.to_series(), '.-')

Trying to set style directly when plotting from DataArray doesn't work:

>>> arr.plot(style='.-')
AttributeError: Unknown property style
>>> arr.plot.line(style='.-')
AttributeError: Unknown property style

Passing DataArray to pyplot.plot() loses index:

>>> plt.plot(arr, '.-')
# works but loses coords; same as plot.plot(arr.values, '.-')

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported examples for DataArray.plot, DataArray.plot.line, and pyplot.plot, comparing them with the working to_series() cases. Trace how style arguments and DataArray coordinates are passed through these plotting entry points; done means style='.-' works and pyplot.plot(arr, '.-') retains the coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.