Skip to content

Histogram plot of DataArray can be extremely slow #908

@maahn

Description

@maahn

The speed of plotting a histogram of a large DataArray depends a lot how you do it:

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt

nPoints = 100000
data = xr.DataArray(np.random.random(nPoints),dims=['time'],coords=[np.arange(nPoints)])

It take sonly some ms if you use

plt.figure()
%time data.plot.hist()

plt.figure()
%time plt.hist(data.values)

However, if you omit .values it takes extremely long:

In [12]: %time plt.hist(data)
CPU times: user 2min, sys: 9.73 s, total: 2min 9s
Wall time: 2min 3s

Do if one forgets to add .values or to use xarray's plot routine, one can be stuck for a long time. I have to kill python 1-2 per day due to that issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions