Skip to content

Matplotlib interfering with NumPy (on Windows) #18977

@lfaucheux

Description

@lfaucheux

Are you aware of this issue raised by @Keepalive, fully reproducible/replicable (replicated by @QuangHoang), explained on SO at Matplotlib interfering with NumPy (on Windows) ?

Brief description

np.linalg.matrix_rank returns unexplicable 0s as soon as matplotlib.pyplot.plot is called with a restricted set of linestyles.

Environment

Python3.7.3

numpy==1.19.2      # >=1.19.0 actually
matplotlib==3.3.3  # >=3.1.3 for what @keepalive can tell

Replication

import numpy as np
import matplotlib.pyplot as plt
import joblib as jl

linestyles = [
    'solid', '-',
    'dotted',  # '.', => ValueError: '.' 
    'dashed', '--',
    'dashdot', '-.',
    ':', '', ' '    
]

for ls in linestyles:
    print(26*'*', f"linestyle='{ls}'")
    
    np.random.seed(1010)
    x  = np.random.rand(9, 5)
    h0 = jl.hash(x)
    
    x_vals = y_vals = np.arange(0, .5, .05)
    plt.plot(x_vals, y_vals, linestyle=ls)
    # plt.show()
    
    h1 = jl.hash(x)
    mr = np.linalg.matrix_rank(x)
    print(
        '\t', mr, (not mr)*'<---------------[!!!]'
    )
    print('\t', 'Has not changed:', h0 == h1)

0rank4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions