ContextLab / hypertools

A Python toolbox for gaining geometric insights into high-dimensional data
http://hypertools.readthedocs.io/en/latest/
MIT License
1.81k stars 161 forks source link

plotting with hypertools overwrites existing matplotlib style #243

Closed paxtonfitzpatrick closed 3 years ago

paxtonfitzpatrick commented 3 years ago

I'm not entirely sure why this happens, but calls to hypertools.plot seem to alter the style of subsequent non-hypertools plots. Example:

import numpy as np
import hypertools as hyp
import matplotlib.pyplot as plt

%matplotlib inline    # running in a notebook
geo = hyp.load('weights_avg')
plt.plot(np.arange(10))
plt.show()

Screen Shot 2020-10-06 at 8 46 27 PM

geo.plot(animate=False, legend=['first', 'second'], show=True)

Screen Shot 2020-10-06 at 8 46 51 PM

plt.plot(np.arange(10))
plt.show()

Screen Shot 2020-10-06 at 8 47 14 PM

Although I don't see this explicitly happening anywhere in the code, it appears that hypertools is updating the rcParams:

import numpy as np
import hypertools as hyp
import matplotlib.pyplot as plt
%matplotlib inline
geo = hyp.load('weights_avg')

plt.plot(np.arange(10))
plt.close()

rcparams_before = (plt.rcParams).copy()

geo.plot(animate=False, legend=['first', 'second'], show=False)
plt.close()

rcparams_after = (plt.rcParams).copy()

plt.plot(np.arange(10))
plt.close()

for k, v in rcparams_before.items():
    if v != rcparams_after[k]:
        print(f'{k}\n\tbefore: {v}\n\tafter: {rcparams_after[k]}\n')

Output:

axes.axisbelow
    before: line
    after: True

axes.edgecolor
    before: black
    after: .8

axes.grid
    before: False
    after: True

axes.labelcolor
    before: black
    after: .15

axes.prop_cycle
    before: cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
    after: cycler('color', [(0.86, 0.3712, 0.33999999999999997), (0.33999999999999997, 0.8287999999999999, 0.86)])

figure.facecolor
    before: (1, 1, 1, 0)
    after: white

font.sans-serif
    before: ['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
    after: ['Arial', 'DejaVu Sans', 'Liberation Sans', 'Bitstream Vera Sans', 'sans-serif']

grid.color
    before: #b0b0b0
    after: .8

image.cmap
    before: viridis
    after: rocket

interactive
    before: True
    after: False

lines.solid_capstyle
    before: projecting
    after: round

patch.edgecolor
    before: black
    after: w

patch.facecolor
    before: C0
    after: (0.86, 0.3712, 0.33999999999999997)

patch.force_edgecolor
    before: False
    after: True

text.color
    before: black
    after: .15

xtick.bottom
    before: True
    after: False

xtick.color
    before: black
    after: .15

ytick.color
    before: black
    after: .15

ytick.left
    before: True
    after: False

I think I know how to handle this, so I'll take care of this when I fix #242 as well