0

I have a vector A of size 88 A= [n1,n2,...,n88] Each value of the vector has a sensor voltage intensity reading that range from 0 to 1. I want to transform those intensity values to pixel intensity values as in the following image: enter image description here The image has 280 x 420 pixeles where the 88 sensors are evenly distributed. White color represents a reading of 0 and black color represents a reading of 1. Can someone please tell me how can I implement this in Python using matplotlib? Thank you.

user3025898
  • 561
  • 1
  • 6
  • 19

1 Answers1

2
from pylab import figure, show, rand, colorbar
from matplotlib.patches import Ellipse
from matplotlib.collections import PatchCollection
from matplotlib import cm

#dummy data
A = rand(88)

#todo: are the i and j loops in the right order for the data?
spots = [Ellipse(xy=(i*475/11. + 18,j*275/8. + 16 + 16*(i%2 > 0)),
                 width=20, height=25)
        for i in range(11) for j in range(8)]

fig = figure()
ax = fig.add_subplot(111, aspect='equal')

p = PatchCollection(spots, cmap=cm.cubehelix_r)
p.set_array(A)
p.set_edgecolor('face')
ax.add_collection(p)
colorbar(p)

ax.set_xlim(0, 420)
ax.set_ylim(280, 0)

show()

enter image description here

cphlewis
  • 15,759
  • 4
  • 46
  • 55
  • Hi Cphlewis, Thank you for your answer! the results is perfect. You just showed me many functions from matplotlib that I did not know about. the sensor arrangement and shape (as you asked) is as in the following image: [link](https://www.dropbox.com/s/hu5kdopakhxxxyw/sensorarrangement.PNG?dl=0) Do you know where I can find the availible colors (as cubehelix_r) for the color bar? Since I want it to be as similar as possible. Thank you again! – user3025898 Mar 16 '15 at 09:53
  • You can define your own colormap (http://matplotlib.org/api/colors_api.html) : cubehelix_r was just the closest one from the standard set. – cphlewis Mar 16 '15 at 10:10
  • Hi Cphlewis, as you can see in the image the sensor allocation goes from bottom to top and left to right. also the first eight sensor columns have 7 sensors, then the ninth column has 6 sensors, the tenth 7 sensors, the eleventh 6 sensors, the twelve 7 sensors and the thirteenth 6 sensors for a total of 88 sensors. can you please help me modify your program to reflect this change? Thank you. – user3025898 Mar 16 '15 at 12:46
  • @user3025898 Everything you need to change should be in this line: `spots = [Ellipse(xy=(i*475/11. + 18,j*275/8. + 16 + 16*(i%2 > 0)), width=20, height=25) for i in range(11) for j in range(8)]` – castle-bravo Mar 16 '15 at 15:23
  • I'll leave modifying the xy-definitions to you, since (a) you can do it by experimenting with the code (b) it's so specific to your sensor layout (c) it's basically algebra and _hint_ (d) you could just type in a list `[(x1,y1), (x2, y2) ...]` of sensor centers and use that as your for-loop. – cphlewis Mar 16 '15 at 21:10
  • Ok that is all I need, again thanks for your help :) – user3025898 Mar 17 '15 at 09:59