ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  2D plot
Posted by Margherita Vittone on Apr-09-2013 02:38
Attachments:
Hi,
i need to create a 2D plot which will represent a 9x9 grid of pixel square cells.
On the x and y axis, positions will be shown in the range -40,40 with a
10 increment.
Each cell (10x10) will represent a beam intensity which will be shown as colored
squared (color mapping according to the intensities); so this is a chart
with x0,y0,z0 set of data.
Surface charts are not useful because of interpolation and users want to see a square
colored cell. I was thinking to try to use the 3D scatter bubble chart ,which it might be
acceptable (http://www.advsofteng.com/gallery_3dscatter.html) but i can't find any examples
in our downloaded sets of example under the pythondemo directory.
I haven't seen any way in chart director to be able to reproduce what i need
(which had been previously done using a different plotting tool).
If you have any suggestion this would be great!
Thank you very much
Margherita
pixels.png

  Re: 2D plot
Posted by Peter Kwan on Apr-09-2013 05:53
Attachments:
Hi Margherita,

I think for your case, using a normal scatter chart (or 2D bubble chart) may be suitable. I have attached an example for your reference.

Basically, the example simply split your data into groups, with each group representing the points of a certain color. Each of the groups is then plotted as a scatter layer with rectangular symbols.

Hope this can help.

Regards
Peter Kwan
test.png
test.py
#!/usr/bin/python
from pychartdir import *

# The z-data for the 81 cells
dataZ = RanSeries(1).getSeries(81, 0, 100)

# The coloring method
colorMap = [
	#color, minValue, maxValue
	[0xff3333, 70, 100],
	[0xffff00, 30, 70],
	[0x66ff66, 0, 30]
	]

# Size of the cells in pixels
cellSizeInPixels = 30

# Configure chart size, plot area location and legend box location
c = XYChart(200 + 9 * cellSizeInPixels, 100 + 9 * cellSizeInPixels)
c.setPlotArea(50, 50, 9 * cellSizeInPixels, 9 * cellSizeInPixels)
c.addLegend(c.getPlotArea().getRightX() + 20, 50, 1, "arial.ttf", 8)

# Axis scale
c.xAxis().setRounding(0, 0)
c.xAxis().setLinearScale(-45, 45, 10)
c.yAxis().setRounding(0, 0)
c.yAxis().setLinearScale(-45, 45, 10)

# Create a bubble layer for each color
for color, minValue, maxValue in colorMap :

	# get the x and y coordinates for points within minValue and maxValue
	dataX = []
	dataY = []
	for i in [i for i in xrange(81) if dataZ[i] >= minValue and dataZ[i] <= maxValue]:
		dataX.append(-40 + 10 * (i % 9))
		dataY.append(-40 + 10 * (i // 9))

	# draw the points
	c.addScatterLayer(dataX, dataY, "From %d to %d" % (minValue, maxValue), SquareSymbol, 11, 
		color, color).setSymbolScale([10] * len(dataX), XAxisScale, [10] * len(dataY), YAxisScale)
	
c.makeChart("test.png")