Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

cbook._reshape_2D flattens ndarray with 2 dims (rectangular ndarray) #8092

Open
Labels
API: consistencykeepItems to be ignored by the “Stale” Github Action
@lcapalleja

Description

@lcapalleja

Bug report

boxplot throwing an error (below) when x is an ndarray with len(x.shape)==2 (I.E. when x is rectangular).

ValueError: List of boxplot statistics and 'positions' values must have same the length

Code for reproduction

importnumpyasnpimportmatplotlib.pyplotasplta=np.array([np.array([1,2,3,4]),np.array([3,2,7,4]),np.array([3,9,3,1,6])])b=np.array([np.array([1,2,3,4]),np.array([3,2,7,4]),np.array([3,9,3,1])])# Ragged ndarray works correctlyplt.boxplot(x=a,positions=range(len(a)))# Rectangular ndarray throws error (above)plt.boxplot(x=b,positions=range(len(b)))

Matplotlib version

  • matplotlib 1.5.3 np111py35_0
  • python 3.5.2
  • Windows Server 2012 R2 Standard
  • conda installation

Possible cause

I believe the issue is in cbook._reshape_2D in the line below. I am not sure why that logic is in place but assume it is for good reason.

X= [X[:,i]foriinxrange(ncols)]

Got there by looking in:

  1. _axes.boxplot
  2. _axes.bxp
  3. cbook.boxplot_stats

reference _reshape_2D:

def_reshape_2D(X):"""    Converts a non-empty list or an ndarray of two or fewer dimensions    into a list of iterable objects so that in        for v in _reshape_2D(X):    v is iterable and can be used to instantiate a 1D array.    """ifhasattr(X,'shape'):# one itemiflen(X.shape)==1:ifhasattr(X[0],'shape'):X=list(X)else:X= [X, ]# several itemseliflen(X.shape)==2:nrows,ncols=X.shapeifnrows==1:X= [X]elifncols==1:X= [X.ravel()]else:X= [X[:,i]foriinxrange(ncols)]else:raiseValueError("input `X` must have 2 or fewer dimensions")ifnothasattr(X[0],'__len__'):X= [X]else:X= [np.ravel(x)forxinX]returnX

Current Workaround
Converting the ndarray to a list of lists. The necessity for this workaround doesn't really make sense especially since the plotting works fine with a ragged/non-rectangular ndarray but does not work with a rectangular ndarray.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: consistencykeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp