0

I have data similar in this format

f = [
  ((0, 2), 519.52876712328771), 
  ((0, 3), 514.56307692307701), 
  ((0, 4), 564.86538461538464), 
  ((1, 1), 641.70774647887322), 
  ((1, 2), 537.97177419354841), 
  ((1, 3), 529.85214285714301), 
  ((1, 4), 467.36338028169018)
]

I want to plot a checkerboard color plot of box 1 unit size. The location or the (x,y) co-ordinate will be given by f[i][0] and the color will be given by f[i][1]. As one can see the chekerboard plot will not fill up the entire image.

How would I do this in python using matplotlib?

Fabian N.
  • 3,807
  • 2
  • 23
  • 46
james_l
  • 3
  • 2
  • http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set – furas Jan 26 '16 at 06:58

1 Answers1

0

Example:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

f = [((0, 2), 519.52876712328771), ((0, 3), 514.56307692307701), ((0, 4), 564.86538461538464), ((1, 1), 641.70774647887322), ((1, 2), 537.97177419354841), ((1, 3), 529.85214285714301), ((1, 4), 467.36338028169018)]
x = []
y = []
value = ['red', 'blue', 'green', 'brown', 'black', 'aqua', 'violet']
for i in range(0, len(f)):
    j = f[i][0][0]
    k = f[i][0][1]
    x.append(j)
    y.append(k)

fig = plt.figure()
ax = fig.add_subplot(111)

ax.axis([0, max(y), 0, max(y)])

for axis in [ax.xaxis, ax.yaxis]:
    axis.set_minor_locator(MultipleLocator(1))
    axis.set_ticks(np.arange(max(y)) + 0.5)
    axis.set_ticklabels(range(max(y)))
for i in range(0, len(f)):
    rect = plt.Rectangle((x[i],y[i]), 1, 1, color=value[i])
    ax.add_patch(rect)

ax.grid(which='minor')

plt.show()

Output:

enter image description here

Just use our own colors. Hope this helps!

VlS
  • 586
  • 3
  • 13