SourceForge logo
SourceForge logo
Menu

Re: [matplotlib-devel] Better defaults all around?

From: Derek H. <de...@as...> - 2014年11月26日 20:53:47
On 26 Nov 2014, at 07:53 pm, Chris Barker <Chr...@no...> wrote:
> On Wed, Nov 26, 2014 at 1:30 AM, Todd <tod...@gm...> wrote:
>> About this, I am not expert so forgive me if this is nonsensical. However, it would seem to me that these requirements are basically the same as the requirements for the new default colormap that prompted this whole discussion. So, rather than create two inconsistent set of colors that accomplish similar goals, might it be better to instead use the default colormap for the line colors? You could pick "N" equally-spaced colors from the colormap and use those as the line colors.
>> 
> I'm no expert either, but while similar principles about colorblind compatibility, etc apply, you want to sue a different scheme to represent a continuous range of colors and a set of distinct colors that aren't intended to be ranked.
> 
I’ve also become throughly annoyed with the default colour cycle, especially with its
glaring cyan-magenta contrast, and found it desirable to have an easier way to
customise this either explicitly or by changing color_cycle.
As there are already a couple of sequences existing in the available colourmaps that
could be useful for different purposes or tastes, what’s lacking in particular in my view
is an easier-to-use interface to draw colours from those maps; I think that’s along the
lines of what Todd also has suggested further down in his mail.
I’ve written a little utility I’m simply appending because it’s so short, which returns an
array of colours of specified length that could be passed to axes.color_cycle or just
explicitly used as crange[i]. Also useful to colour scatter plot markers according to a
certain quantity (pass this quantity as "values" to crange).
Regarding to the above, I think sometimes the line colour requirements are similar to
those for a general colourmap, e.g. I often want to plot a series of lines like different
spectra, which are easily enough distinguishable, but should IMO reflect a certain
continuous trend like different temperatures - are ranked, IOW - and thus would be well
represented by a sequence of values from "heat" or "coolwarm". However there are still
some additional requirements, as you’d generally want every colour to have enough
contrast on a white or bright background canvas. In the example below I’ve added a
"max_lum" keyword to darken whitish or yellow colours appropriately.
This is probably not extremely sophisticated in terms of colour physiology, but if you
have a suggestion if and where it could be added to matplotlib, I could go ahead and
make a pull request (and try to find the time to add some tests and examples).
Cheers,
						Derek
def crange(cmap, values, max_lum=1, start=0, stop=255, vmin=None, vmax=None):
 """
 Returns RGBA colour array of length values from colormap cmap
 cmap: valid matplotlib.cm colormap name or instance
 values: either int - number of colour values to return or
 array of values to be mapped on colormap range
 max_lum: restrict colours to maximum brightness (1=white)
 start,stop: range of colormap to use (full range 0-255)
 vmin,vmax: input values mapped to start/stop (default actual data limits)
 """
 try:
 if np.isscalar(values):
 vrange = np.linspace(start,stop,np.int(values))
 else:
 v = np.array(values).astype(np.float)
 vmin = vmin or v.min()
 vmax = vmax or v.max()
 vrange = start+(v-vmin)*(stop-start)/(vmax-vmin)
 except (ValueError, TypeError) as err:
 print("invalid input values: must be no. of colours or array: %s" %
 err)
 return None
 vrange = np.uint8(np.round(vrange))
 cmap = matplotlib.cm.get_cmap(cmap)
 lcor = (1.0-max_lum) / 9
 crange = cmap(vrange)
 crange[:,:3] *= (1-crange[:,:3].sum(axis=1)**2*lcor).reshape(-1,1)
 return crange

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /