Color Parsing Bug

There seems to be an issue with how arguments are parsed when it comes
to determining the color of a line. Generally, it seems that 'c'
takes precedence over 'color'. However, this precedence seems to
change with the number of passed kwargs.

···

-------------

import matplotlib.pyplot as plt
import numpy as np

# 'c' seems to have precedence over 'color'
plt.plot(np.arange(10)-2, c='b', color='r') # line is blue
plt.plot(np.arange(10)-1, color='r', c='b') # line is blue

# But...
x = {'c': 'b',
'color': 'r',
'label': 'blah',
'linestyle': '-',
'linewidth': 3,
'marker': None}

# Some strange parsing error
plt.plot(np.arange(10)+1, **x) # line is red
del x['marker'] # delete any key but 'c' or 'color'
plt.plot(np.arange(10)+2, **x) # line is blue
x['zorder'] = 3 # add back any key
plt.plot(np.arange(10)+3, **x) # line is red

plt.show()

Yeah, there is a bit of a can of worms here. I suspect that part of the issue has to do with dictionaries not guaranteeing order, but I can’t figure out where that would happen, though. In the plot handling code, we are explicitly looking for the “color” kwarg, never the ‘c’ kwarg. It is over in the Line2D class that the “c” kwarg ever gets obtained. In that situation, what is likely happening is that the plot() code creates the Line2D object, passing the “color” kwarg that it extracted, and any other kwargs to the Line2D constructor (such as the ‘c’ kwarg). My guess is that the whole aliasing system is rather ad-hoc, and actually doesn’t have explicit precedence because it was never intended for both kwargs to appear at the same time.

Could you file an issue on the github tracker about this?

Thank you,
Ben Root

···

On Tue, Oct 16, 2012 at 6:36 PM, T J <tjhnson@…149…> wrote:

There seems to be an issue with how arguments are parsed when it comes

to determining the color of a line. Generally, it seems that ‘c’

takes precedence over ‘color’. However, this precedence seems to

change with the number of passed kwargs.