SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S




1
(2)
2
(3)
3
4
(3)
5
(11)
6
(3)
7
(2)
8
(6)
9
(6)
10
(8)
11
(3)
12
(7)
13
(8)
14
(5)
15
(11)
16
(11)
17
(3)
18
(2)
19
(7)
20
(11)
21
(6)
22
(5)
23
(1)
24
25
26
(6)
27
(3)
28
(8)
29
(2)
30
(1)

Showing 2 results of 2

From: Chloe L. <ch...@be...> - 2012年11月07日 17:34:47
> 
> I think a histogram isn't the thing I need because it is not important
> when (the time) the values between 60 and 90 have been "created". Only
> the values and the amount of values is important.
You can make the values the independent axis of the histogram.
> 
> Also when talking about a colormap I'm not sure if this is required. In
> the end I want only one color (blue) in a rectangle that changes the
> color/appearance based on the density. So I guess to bluescale it is the
> right way as you suggested.
> 
I think custom blue scale can only be done as a custom colormap; but R and G will be constant throughout.
&C
From: <ra...@0x...> - 2012年11月07日 13:26:24
Hi!
I think a histogram isn't the thing I need because it is not important
when (the time) the values between 60 and 90 have been "created". Only
the values and the amount of values is important.
Also when talking about a colormap I'm not sure if this is required. In
the end I want only one color (blue) in a rectangle that changes the
color/appearance based on the density. So I guess to bluescale it is the
right way as you suggested.
And as you said, the min density value would be 60 and the max density
value would be 90. I think I will make those values fix.
As you told the "colorbar" might not mean the same on a later time. This
is no problem and basically the goal of it.
Cool, I guess this is the concept to be implemented. I'm searching for
ways to bluescale with matplotlib..
I have hacked a little code snipped. I think it does what I desire,
except of one thing left. Some of the little "elements" I draw do
overlap and I dont know why. I print the values to plot on the x-axis to
the console. As you see the x-coordinates do not overlap.. Does anyone
know what the problem is?
from matplotlib.ticker import MultipleLocator
import numpy as np
import matplotlib.pyplot as plt
import random
import array
from pylab import gca
# Source:
http://stackoverflow.com/questions/8500700/how-to-plot-a-gradient-color-line-in-matplotlib
#CONSTANTS
NPOINTS = 100
COLOR='blue'
RESFACT=10
MAP='winter' # choose carefully, or color transitions will not appear smooth
FIGRES=111.0 # figure size: must be float!
# create random data
np.random.seed()
x = []
tmp = 0
while tmp < NPOINTS:
 x.append(random.randrange(60, 98, 1))
 tmp = tmp+1
fake_y_array = np.array([0])
a = 0
while a < NPOINTS-1:
 fake_y_array = np.append(fake_y_array, 0)
 a = a+1
y = fake_y_array
x = sorted(x)
#print x
fig = plt.figure()
ax4 = fig.add_subplot(FIGRES) # high resolution alpha
npointsHiRes = len(x)
stats = dict()
for index in x:
 #stats.insert(index, stats[index] + 1)
 try:
 stats[index] = stats[index] + 1
 except:
 stats[index] = 1
print stats
# alpha is the transparency parameter
# based on the more values we have, the smaller is the
# difference between transparency per element in the graph
# we multiply this alpha with a given factor to make the elements
# appear visible enough for the human eye
alpha_steps = (1.0/len(stats))*1
for i in range(npointsHiRes):
 #print 'x: ' + str(x[i])
 #print 'stats: ' + str(stats[x[i]]) + ' (a) ' +
str(alpha_steps*stats[x[i]])
 if x[i] is x[i-1]:
 # skip this round because we already
 # have drawn one element
 # and based on its transparency
 # it is expressed how many times this
 # value exists
 continue
 ytmp = y[i:i+2]
 xtmp = x[i:i+2]
 try:
 if xtmp[0] is xtmp[1]:
 # ok if they equal, we cannot draw a visible line
 # +1 to draw it..
 xtmp[1] = xtmp[1]+1
 except IndexError:
 # last element is sometimes "alone"
 # so we add an effectively last one
 # to draw it with eye-visibility
 xtmp.append(xtmp[0]+1)
 a = np.array([0])
 ytmp = np.hstack((ytmp, a))
 ax4.plot(xtmp,ytmp,
 alpha=alpha_steps*stats[x[i]],
 color=COLOR, lw=100) #drawstyle: [ 'default' | 'steps' |
'steps-pre' | 'steps-mid' | 'steps-post' ]
ax4.set_xlim(min(x),max(x)+1)
gca().xaxis.set_major_locator(MultipleLocator((round(len(x)/FIGRES))*2))
gca().yaxis.set_major_locator(MultipleLocator())
plt.grid(True)
#fig.savefig('gradColorLine.png')
plt.show()
On 11/06/2012 01:25 AM, Chloe Lewis wrote:
> You're translating a histogram of your data into a colormap, yes? 
> 
> The matplotlib histogram returns bins and patches, which you could translate into color intensities; but I bet scipy.stats.histogram would be easier. Then the bin centers are the segment boundaries of the colormap, and the weight in each bin is the respective color intensity.
> 
> Also, color has a finite extent but the bin weight might not. You'll need to choose a nominal max value to norm the colors to, and decide whether to use the same max value all the time (so early plots might all be light, late plots all dark) or calculate it from the data each time you plot (in which case the colorbar this month might not mean the same thing as the color bar last month). 
> 
> I think using all three of RGB is too confusing -- do it bluescale or grayscale. 
> 
> &C
> 
> 
> 
> 
> On Nov 5, 2012, at 7:13 AM, ra...@0x... wrote:
> 
>> Hi Chloe
>>
>> Thank you for answering.
>>
>> I agree the way you suggest. Currently I have done this:
>>
>> import matplotlib
>> import matplotlib.pyplot as plt
>>
>> # http://matplotlib.org/examples/api/colorbar_only.html
>> #
>> http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap
>>
>>
>> # The lookup table is generated using linear interpolation for each
>> primary color, with the 0-1 domain divided into any number of segments.
>> # x, y0, y1
>> cdict = {'red': [(0.0, 0.0, 0.0),
>> (0.5, 1.0, 1.0),
>> (1.0, 1.0, 1.0)],
>>
>> 'green': [(0.0, 0.0, 0.0),
>> (0.25, 0.0, 0.0),
>> (0.75, 1.0, 1.0),
>> (1.0, 1.0, 1.0)],
>>
>> 'blue': [(0.0, 0.0, 0.0),
>> (0.5, 0.0, 0.0),
>> (1.0, 1.0, 1.0)]}
>>
>> # create colormap
>> my_cmap = matplotlib.colors.LinearSegmentedColormap("my_colormap",
>> cdict, N=256, gamma=1.0)
>>
>> # optional: register colormap
>> #plt.register_cmap(name='my_colormap', data=cdict)
>>
>> fig = plt.figure(figsize=(5,1))
>> fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
>> plt.axis("off")
>> import numpy as np
>> a = np.linspace(0, 1, 256).reshape(1,-1)
>> a = np.vstack((a,a))
>> plt.imshow(a, aspect='auto', cmap=my_cmap, origin='lower')
>>
>> plt.show()
>>
>> Now the tricky part has still to be done. I have a varying number (ca.
>> 500, increasing) of values between 60 and 90. Those values must be
>> represented in the colorbar. White if there is no value, blue towards
>> black the more values are in the same area.
>> For this, I guess, I have to set a x for each value (and three x since
>> the color is calculated using RGB). And the closer it is to the previous
>> one the more I have to calculate the color between blue and black.
>>
>> Or do you suggest another way to implement this?
>>
>> I do not know of any other software that this issue has been implemented.
>>
>> cheers!
>>
>>
>> On 10/26/2012 07:47 PM, Chloe Lewis wrote:
>>> you'll be doing something like the second color bar, but making the
>>> boundary and color definitions a lot more flexible. Where the discrete
>>> color bar uses
>>>
>>> cmap = mpl.colors.ListedColormap(['r', 'g', 'b', 'c'])
>>> bounds = [1, 2, 4, 7, 8]
>>>
>>> you'll be making a whole LinearSegmentedColormap, see
>>>
>>> http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap
>>>
>>> and check out specifically the ascii-art explanation of interpolation between row[i] and row[i+1]. Red, green, blue will break based on your data density and how you want to express 'intensity'. And depending on whether you'll make it red-green-colorblindness neutral!
>>>
>>> Interesting problem. Has it been implemented in some other software?
>>>
>>>
>>> Chloe Lewis 
>>> PhD candidate, Harte Lab
>>> Division of Ecosystem Sciences, ESPM
>>> University of California, Berkeley
>>> 137 Mulford Hall
>>> Berkeley, CA 94720
>>> ch...@be... <mailto:ch...@be...>
>>>
> 

Showing 2 results of 2

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 によって変換されたページ (->オリジナル) /