Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color_cycle warning with matplotlib 1.5 #68

Closed
chadkennedyonline opened this issue Nov 10, 2015 · 5 comments
Closed

color_cycle warning with matplotlib 1.5 #68

chadkennedyonline opened this issue Nov 10, 2015 · 5 comments

Comments

@chadkennedyonline
Copy link

When executing

#format the book
%matplotlib inline
%load_ext autoreload
%autoreload 2  
from __future__ import division, print_function
import sys
sys.path.insert(0,'./code')
from book_format import load_style
load_style()

from any page, I get the following warning:

D:\Chad\Documents\WinPython-64bit-3.4.3.6\python-3.4.3.amd64\lib\site-packages\matplotlib\__init__.py:876: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

This Python distro is using Matplotlib 1.5.0rc3. I have confirmed that changing the axes.color_cycle line in 538.json to

  "axes.prop_cycle": "cycler('color', ['#6d904f','#013afe', '#202020','#fc4f30','#e5ae38','#A60628','#30a2da','#008080','#7A68A6','#CF4457','#188487','#E24A33'])",

fixes the warning. But I am unsure how to make the json file conditional based on Matplotlib version, so as to be backwards compatible with older distributions.

@rlabbe
Copy link
Owner

rlabbe commented Nov 14, 2015

I just pushed a version that detects the matplotlib version and uses the appropriate settings. Let me know if it doesn't work for you.

@dnstanciu
Copy link
Contributor

Hi, I downloaded a fresh copy and I get this error when running the snippet posted by @chadkennedyonline :

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-25-a550bbe40f47> in <module>()
      7 sys.path.insert(0,'./code')
      8 from book_format import load_style
----> 9 load_style()

/home/dragos/Projects/Kalman-and-Bayesian-Filters-in-Python/code/book_format.pyc in load_style(directory, name)
    130         s.pop("axes.color_cycle", None)
    131 
--> 132     plt.rcParams.update(s)
    133     reset_axis ()
    134     np.set_printoptions(suppress=True)

ValueError: dictionary update sequence element #0 has length 1; 2 is required

When I print (s), I get 1. I'm guessing that rcParams expects a (key,value) pair. Could you please fix this? Not being able to run the first cell messes up the formatting... Thank you!

@rlabbe
Copy link
Owner

rlabbe commented Nov 18, 2015

@dnstanciu can you tell me your environment - Python version, IPython version, OS, python package if you are using one(anaconda or whatever)? Also the matplotlib version, as my code change behaves differently based on the matplotlib version. I cannot duplicate this here, so I'm hoping this will help me diagnose the problem.

Follow up: you said when you print s you get '1'? As in the number 1? When I print s I get

{'figure.facecolor': '#ffffff', 'font.size': 14.0, 'figure.subplot.hspace': 0.5, 'examples.directory': '', 'axes.grid': True, 'ytick.major.size': 0, 'figure.subplot.bottom': 0.07, 'axes.facecolor': '#ffffff', 'axes.color_cycle': ['#6d904f', '#013afe', '#202020', '#fc4f30', '#e5ae38', '#A60628', '#30a2da', '#008080', '#7A68A6', '#CF4457', '#188487', '#E24A33'], 'savefig.edgecolor': '#f0f0f0', 'axes.linewidth': 3.0, 'grid.linestyle': '-', 'patch.linewidth': 0.5, 'savefig.facecolor': '#f0f0f0', 'axes.axisbelow': True, 'axes.labelsize': 'large', 'axes.edgecolor': '#f0f0f0', 'xtick.minor.size': 0, 'grid.color': '#cbcbcb', 'patch.edgecolor': '#f0f0f0', 'legend.scatterpoints': 1, 'legend.fancybox': True, 'lines.linewidth': 3, 'axes.titlesize': 'x-large', 'figure.subplot.right': 0.95, 'lines.solid_capstyle': 'butt', 'ytick.minor.size': 0, 'grid.linewidth': 2.0, 'xtick.major.size': 0, 'figure.subplot.left': 0.08}

The first lines of the load_style() function read:

if sys.version_info[0] >= 3:
    s = json.load(open(os.path.join(directory, "code/538.json")))
else:
    s = json.load(open(directory + "/code/538.json"), object_hook=_decode_dict)

I suspect you are not reading the 538.json file for some reason. Are you in the base directory for the book? This code uses relative directories, where directory parameter has the default value '.'.

@dnstanciu
Copy link
Contributor

When I got the error, my setup consisted of:
Python 2.7.6; IPython 4.0.0; Ubuntu 14.04; not using anaconda; matplotlib 1.3.1; running ipython notebook from the base directory.

After updating all my PIP packages, I got a new error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-34-a550bbe40f47> in <module>()
      7 sys.path.insert(0,'./code')
      8 from book_format import load_style
----> 9 load_style()

/home/dragos/Projects/testkalmanbook/Kalman-and-Bayesian-Filters-in-Python/code/book_format.py in load_style(directory, name)
    127 
    128     if version[0] > 1 or (version[0] == 1 and version[1] >= 5):
--> 129         s["axes.prop_cycle"] = "cycler('color', ['#6d904f','#013afe', '#202020','#fc4f30','#e5ae38','#A60628','#30a2da','#008080','#7A68A6','#CF4457','#188487','#E24A33'])"
    130         s.pop("axes.color_cycle", None)
    131 

TypeError: 'unicode' object does not support item assignment

I realized that the s dictionary was being overwritten in line 127:

version = [int(s) for s in matplotlib.__version__.split('.')]

That explains why I was getting 1 instead of the JSON settings...
So I changed s to version_no in line 126 and it all works ok now! I've submitted a pull request, if you'd like to accept my small contribution: #70 . Cheers!

@rlabbe
Copy link
Owner

rlabbe commented Nov 24, 2015

I've accepted the pull request (thanks!) and haven't heard of any more problems, so I'm closing it. Please reopen if you are still having problems.

@rlabbe rlabbe closed this as completed Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants