Reputation: 7486
I have the following numpy array :
([[ 0, 0, 0, 0, 0, 0, 27, 541, 1296, 10000],
[ 0, 0, 0, 0, 1, 44, 355, 1998, 3272, 10000],
[ 0, 0, 0, 2, 18, 209, 1069, 3239, 4670, 10000],
[ 0, 0, 0, 10, 96, 486, 1522, 3954, 5379, 10000],
[ 0, 0, 2, 28, 216, 748, 2127, 4769, 6011, 10000],
[ 0, 0, 18, 82, 379, 1200, 2867, 5395, 6528, 10000],
[ 0, 3, 39, 147, 599, 1489, 3237, 5740, 6909, 10000],
[ 0, 6, 48, 246, 759, 1777, 3610, 6034, 7144, 10000],
[ 0, 12, 90, 324, 1009, 2072, 3980, 6365, 7466, 10000],
[ 1, 12, 119, 438, 1103, 2337, 4215, 6594, 7568, 10000]])
what i want to is to create grey-colored table/image where bigger number is darker color. In addition I want to set the x&y axis to defined values.
x-axis : [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
y-axis : [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4200, 4500]
I've been playing with imshow, with unsatisfactory results so far.
fig, ax1 = plt.subplots(1,1)
ax1.imshow(np.flipud(x), cmap='Greys', interpolation='nearest', extent=[100,1001,500,4501])
ax1.set_xticklabels(xaxis)
ax1.set_yticklabels(yaxis)
ax1.grid()
fig.show()
First the image should be square, second interpolation smears the exactness of the range (grid is in the middle of cell not the edge).
Upvotes: 0
Views: 311
Reputation: 1306
Would this be a satisfactory result?
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="white")
cmap = sns.color_palette("Greys", 8)
f, ax = plt.subplots(figsize=(10, 10))
ax = sns.heatmap(x, cmap=cmap, vmax=10000, vmin=0,
square=True, linewidths=.5, cbar_kws={"shrink": .5},
xticklabels=[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
yticklabels=[4500, 4200, 4000, 3500, 3000, 2500, 2000, 1500, 1000, 500])
Upvotes: 4