[Matplotlib-users] plot() question

2012-10-16 Thread ran...@0x06.net
Hi,

I have a 2d array like:

[[64, 13], [66, 22], [68, 9], [70, 11], [72, 8], [74, 10], [76, 11],
[78, 8], [80, 9], [82, 9], [84, 15], [86, 13], [88, 5], [90, 9], [92,
13], [94, 12], [96, 7]]

I'd like to plot a line/graph that goes through all those coordinates
specified in the array.

What I do:

for point in array:
plot(point[0], point[1], 'bo-')

This draws the dots on the graph as desired - but it does not draw the
line between them.

Is the data format wrong?

thanks

--
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] how to express statistical data in colors

2012-10-23 Thread ran...@0x06.net
hi,

I'd like to present data in a colorbar-style graphic.

The data to plot is in this form: [1,2,4,4,4.1,4.3,6,7].
The colorbar with this data should show at the begin the color with low
intensity. In more or less the middle of the colorbar the intensity
should be much more because there are a lot values around 4-4.3 and at
the end the intensity should be low again. I imagine low to middle
intensity to show with the color blue and high intensity with nearly by
or with the color black.

With colobar-style I mean this:
http://matplotlib.org/examples/api/colorbar_only.html (the first bar).

I assume matplotlib already provides such a method I cant find.. so any
input is welcome:)

thank you

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how to express statistical data in colors

2012-11-07 Thread ran...@0x06.net
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, ran...@0x06.net wrote:
> 
>> Hi Chloe
>>
>> Thank you for answering.
>>
>> I agree the way you suggest. Currently I have done this:
>>
>> import matp