#!/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")
|