dylanplummer commited on
Commit
2ff282d
·
1 Parent(s): 83896e7

resort to string img convert

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -177,12 +177,22 @@ def get_heatmap(gene, locus1, locus2):
177
  print(heatmap_locus)
178
  mat = beta_cooler.matrix().fetch(heatmap_locus)
179
  #img = draw_heatmap(mat, 0, return_image=True)
180
- fig, ax = plt.subplots(figsize=(6, 6))
181
- img = ax.imshow(mat, cmap='Reds', norm=PowerNorm(gamma=0.5), interpolation=None)
182
- arr = img.get_array()
183
- print(arr.shape)
 
 
 
 
 
 
 
 
 
 
184
  plt.close()
185
- return arr
186
 
187
  def perturb(gene, locus1, locus2):
188
  locus1 = locus1.replace(',', '')
 
177
  print(heatmap_locus)
178
  mat = beta_cooler.matrix().fetch(heatmap_locus)
179
  #img = draw_heatmap(mat, 0, return_image=True)
180
+ fig, ax = plt.subplots(figsize=(4, 4))
181
+ ax.imshow(mat, cmap='Reds', norm=PowerNorm(gamma=0.5), interpolation=None)
182
+ # remove white padding
183
+ plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
184
+ plt.axis('off')
185
+ plt.axis('image')
186
+
187
+ # redraw the canvas
188
+ fig = plt.gcf()
189
+ fig.canvas.draw()
190
+
191
+ # convert canvas to image using numpy
192
+ img = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
193
+ img = img.reshape(fig.canvas.get_width_height()[::-1] + (3,))
194
  plt.close()
195
+ return img
196
 
197
  def perturb(gene, locus1, locus2):
198
  locus1 = locus1.replace(',', '')