Repository: arviz-devs/arviz

Issue:
arviz-darkgrid not working in example from quickstart
This command is not being recognized.
I installed the program from github on Mac OS 10.13 using macports Python3.5 

az.style.use('arviz-darkgrid')


Discussion:
What is the output if you run:

```python
import os
import arviz

print(os.listdir(os.path.join(os.path.dirname(arviz.__file__), 'plots', 'styles')))
```
This should print out the two style files that currently ship with arviz: `['arviz-whitegrid.mplstyle', 'arviz-darkgrid.mplstyle']`

We had some trouble making sure they actually got installed from pypi, but I just checked on a fresh environment and it was ok. 

Can you also confirm that `arviz.__version__` is `0.2.1`?
arviz.__version__       returns.   '0.2.1'


%matplotlib inline
import arviz as az
import numpy as np

# ArviZ ships with style sheets!
# az.style.use('arviz-darkgrid')

print(os.listdir(os.path.join(os.path.dirname(arviz.__file__), 'plots',
'styles')))
az.plot_posterior(np.random.randn(1000000))

['arviz-whitegrid.mplstyle', 'arviz-darkgrid.mplstyle']

array([<matplotlib.axes._subplots.AxesSubplot object at 0x1143eaf98>],
      dtype=object)

But the figure does not have a dark background.
See attached figure.

On Wed, Oct 24, 2018 at 10:34 PM Colin <notifications@github.com> wrote:

> What is the output if you run:
>
> import osimport arviz
> print(os.listdir(os.path.join(os.path.dirname(arviz.__file__), 'plots', 'styles')))
>
> This should print out the two style files that currently ship with arviz: ['arviz-whitegrid.mplstyle',
> 'arviz-darkgrid.mplstyle']
>
> We had some trouble making sure they actually got installed from pypi, but
> I just checked on a fresh environment and it was ok.
>
> Can you also confirm that arviz.__version__ is 0.2.1?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/arviz-devs/arviz/issues/377#issuecomment-432902880>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AOeSCzNy7CkKGN7W7cSqGPOaxeXjScNjks5uoTFPgaJpZM4X5alY>
> .
>


-- 
Best regards,

Blaine

Blaine Mooers, Ph.D.
Associate Professor
Department of Biochemistry and Molecular Biology
College of Medicine
University of Oklahoma Health Sciences Center
S.L. Young Biomedical Research Center Rm. 466
975 NE 10th Street
<https://maps.google.com/?q=975+NE+10th+Street&entry=gmail&source=g>, BRC
466
Oklahoma City, OK 73104-5419

office: (405) 271-8300   lab: (405) 271-8313

Faculty webpage
<http://basicsciences.ouhsc.edu/biochemmolbiol/Faculty/bio_details/TabId/11753/ArtMID/30702/ArticleID/6430/Mooers-Blaine-HM-PhD.aspx>
   X-ray lab (LBSF)
<http://research.ouhsc.edu/CoreFacilities/LaboratoryofBiomolecularStructureandFunction.aspx>
SSRL
UEC
<https://www-ssrl.slac.stanford.edu/content/about-ssrl/advisory-panels/ssrl-users-organization/members/ssrluo-2016-executive-committee-members>
SSURF
EasyPyMOL <https://github.com/MooersLab/EasyPyMOL> Molecular Graphics
<https://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/moleculargraphicslinks.html>

<https://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/MolecularGraphicsLinks.html>
Small
Angle Scattering
<http://www.oumedicine.com/docs/default-source/ad-biochemistry-workfiles/small-angle-scattering-links-27aug2014.html?sfvrsn=0>
office: (405) 271-8300   lab: (405) 271-8313
e-mail:  blaine-mooers@ouhsc.edu (or bmooers1@gmail.com)

Sorry, picture did not get attached - the plot should look similar to this:

![image](https://user-images.githubusercontent.com/2295568/47499708-a568bc80-d82e-11e8-989e-48f7b50728a6.png)

Hi Colon,

Thank you for your fast response!
Your program Arviz looks very promising. 
Thank you for putting it together.  

I get a white background. 

![plotwhitebackground](https://user-images.githubusercontent.com/15176203/47504719-6dfc0f00-d832-11e8-987b-c0ed014a3177.png)
That is quite confusing - can you share the exact code you are running to get that? 

In the code snippet you posted before, the style-sheet line is commented out.
hi @MooersLab  is this still a problem for you?
Hi aloctavodia and ColCarroll!

Thank you very much for the follow-up question. I apologize for my slow response. 
I found a workaround solution:

```python
import os
import numpy as np
import arviz as az
az.style.use('seaborn-darkgrid')
az.plot_posterior(np.random.randn(1000000))
```
![plot](https://user-images.githubusercontent.com/15176203/48295634-6902a680-e453-11e8-8023-1d627e2dc004.png)

However, when I use:

```python
az.style.use('arviz-darkgrid')
az.plot_posterior(np.random.randn(1000000))
```

![errormessage](https://user-images.githubusercontent.com/15176203/48295636-7029b480-e453-11e8-8823-7b2cc0a44a7b.png)

It is unclear to me why the arviz-darkgrid style is not being found.
Sorry for the delay unfortunately I do not have access to Mac OS neither I am familiar with macports. 

@MooersLab  ArviZ is installed by executing the script `setup.py`, this script, among other tasks, copy the files `arviz-darkgrid.mplstyle` and `arviz-whitegrid.mplstyle` (located inside `arviz/plots/styles/`) to `configdir `. A workaround is to manually copy those files. You can find `configdir ` for your system by doing:
 
```python
from matplotlib import get_configdir 
print(get_configdir())
```

Sorry I could not provide a better solution.
Hi Osvaldo,

Thank you very much for the suggestion. 
The suggestion should have worked, but It did not work for me. 
I copied the two mplstyle files to the following folder using ``` sudo cp```. 

/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib

Now, the command:

```python
az.style.use('arviz-darkgrid')
```
 does not return an error.

After re-installing netcdf4 with pip for python3.6, I was able to obtain the desired result.

For some reason, the setup.py script did not install the mpl files in the target directory.

We can close this issue. 

Best regards,

Blaine


Resolving patch:
diff --git a/arviz/__init__.py b/arviz/__init__.py
--- a/arviz/__init__.py
+++ b/arviz/__init__.py
@@ -2,9 +2,15 @@
 """ArviZ is a library for exploratory analysis of Bayesian models."""
 __version__ = "0.2.1"
 
+import os
 import logging
 from matplotlib.pyplot import style
 
+# add ArviZ's styles to matplotlib's styles
+arviz_style_path = os.path.join(os.path.dirname(__file__), "plots", "styles")
+style.core.USER_LIBRARY_PATHS.append(arviz_style_path)
+style.core.reload_library()
+
 # Configure logging before importing arviz internals
 _log = logging.getLogger("arviz")
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,4 @@
 import codecs
-import shutil
 import os
 import re
 
@@ -15,10 +14,6 @@
 VERSION_FILE = os.path.join(PROJECT_ROOT, 'arviz', '__init__.py')
 
 
-# Ensure matplotlib dependencies are available to copy
-# styles over
-setuptools.dist.Distribution().fetch_build_eggs(['matplotlib>=3.0'])
-
 def get_requirements():
     with codecs.open(REQUIREMENTS_FILE) as buff:
         return buff.read().splitlines()
@@ -28,29 +23,6 @@ def get_long_description():
     with codecs.open(README_FILE, 'rt') as buff:
         return buff.read()
 
-
-def copy_styles():
-    from matplotlib import get_configdir
-    sd = os.path.join(get_configdir(), "stylelib")
-    source = os.path.dirname(os.path.realpath(__file__))
-    lsd = os.path.join(source, 'arviz', 'plots', 'styles')
-    styles = [f for f in os.listdir(lsd)]
-    if not os.path.isdir(sd):
-        os.makedirs(sd)
-    for s in styles:
-        shutil.copy(os.path.join(lsd, s), os.path.join(sd, s))
-
-
-class DevelopStyles(develop):
-    def run(self):
-        copy_styles()
-        develop.run(self)
-
-class InstallStyles(install):
-    def run(self):
-        copy_styles()
-        install.run(self)
-
 def get_version():
     lines = open(VERSION_FILE, 'rt').readlines()
     version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]"
@@ -71,8 +43,4 @@ def get_version():
     long_description=get_long_description(),
     long_description_content_type='text/markdown',
     include_package_data=True,
-    cmdclass={
-        'develop': DevelopStyles,
-        'install': InstallStyles,
-    },
 )


Test patch: