Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot profile color map #971

Merged
merged 5 commits into from
Jul 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions deeptools/plotProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import argparse
import numpy as np
from math import ceil
import matplotlib
matplotlib.use('Agg')
matplotlib.rcParams['pdf.fonttype'] = 42
Expand Down Expand Up @@ -458,6 +459,13 @@ def plotly_hexbin(self):
py.plot(fig, filename=self.out_file_name, auto_open=False)

def plot_heatmap(self):
cmap = ['RdYlBu_r']
if self.color_list is not None: # check the length to be equal to the numebr of plots otherwise multiply it!
cmap = self.color_list
if len(cmap) < self.numplots:
all_colors = cmap
for i in range(ceil(self.numplots / len(cmap))):
cmap.extend(all_colors)
matrix_flatten = None
if self.y_min == [None]:
matrix_flatten = self.hm.matrix.flatten()
Expand All @@ -479,7 +487,6 @@ def plot_heatmap(self):

ax_list = []
# turn off y ticks

for plot in range(self.numplots):
labels = []
col = plot % self.plots_per_row
Expand All @@ -503,9 +510,10 @@ def plot_heatmap(self):

if self.per_group:
title = self.hm.matrix.group_labels[plot]
tickIdx = plot % self.hm.matrix.get_num_samples()
else:
title = self.hm.matrix.sample_labels[plot]

tickIdx = plot
ax.set_title(title)
mat = [] # when drawing a heatmap (in contrast to drawing lines)
for data_idx in range(self.numlines):
Expand All @@ -526,13 +534,12 @@ def plot_heatmap(self):
label = sub_matrix['group']
labels.append(label)
mat.append(np.ma.__getattribute__(self.averagetype)(sub_matrix['matrix'], axis=0))

img = ax.imshow(np.vstack(mat), interpolation='nearest',
cmap='RdYlBu_r', aspect='auto', vmin=localYMin, vmax=localYMax)
cmap=cmap[plot], aspect='auto', vmin=localYMin, vmax=localYMax)
self.fig.colorbar(img, cax=cax)

totalWidth = np.vstack(mat).shape[1]
xticks, xtickslabel = self.getTicks(plot)
xticks, xtickslabel = self.getTicks(tickIdx)
if np.ceil(max(xticks)) != float(totalWidth - 1):
tickscale = float(totalWidth) / max(xticks)
xticks_use = [x * tickscale for x in xticks]
Expand Down