Open blaiseli opened 8 years ago
hi, and thanks for using my function. Could you provide a self-contained example (including sample data) where this error occurs?
Hi,
Here is an example:
import numpy as np
from chr_matplotlib import remappedColorMap as remap_cmap
import matplotlib.pyplot as plt
points = [('7.68987928239', '0.280729370315'),
('0.403355125994', '0.257420349721'),
('0.319425497413', '0.150782099669'),
('3.19054207099', '0.0952249289337'),
('0.534078916888', '0.15178186293'),
('0.736596226609', '0.0010929162768'),
('0.899056652338', '0.000934496816481'),
('0.309946976912', '0.00459535101184'),
('0.638361946925', '0.00146612167208'),
('0.370177086819', '0.150245134832'),
('0.121657100203', '0.00215972597587'),
('0.122506499189', '0.0658473156801'),
('0.276003191681', '0.000727424188575'),
('0.259600782477', '0.000716744224958'),
('0.164641836761', '0.00740714809965'),
('2.10582095699', '1.79222961447'),
('2.1971828267', '0.155913822187'),
('0.554992149494', '0.00697698289841'),
('0.191095467298', '0.00409991936627'),
('0.963385755836', '0.024997641508'),
('0.0571799953669', '0.00961730723704'),
('0.917563254485', '0.521041011654'),
('0.644680960593', '0.521535849968'),
('0.594070937685', '0.023056261455'),
('0.113169545185', '0.00091966353368'),
('1.75169236313', '0.0480105897773'),
('1.53780468971', '0.00776937686566'),
('0.196526472935', '0.00210988614565'),
('0.567520784536', '0.199039515272'),
('0.466345782605', '0.00287884352607'),
('0.0481004349952', '0.000857363745914'),
('5.29981853749', '0.586445108844'),
('5.47841110911', '0.630035973677'),
('0.290957761705', '0.00241011178955'),
('0.318942884353', '0.00154622139921'),
('0.254504388561', '0.0973271017723'),
('0.440027283725', '0.00925537513669'),
('1.79219325114', '1.26906388339'),
('0.441050423413', '0.0022451656848'),
('0.223327584876', '0.000964756713395'),
('0.917389513783', '0.0293918532051'),
('1.13829116368', '0.00476801042364'),
('0.0146199583022', '0.0120303856832'),
('0.519471828267', '0.231622304273'),
('1.49606831227', '0.00961078059261'),
('0.167717690664', '0.139188999163'),
('0.409841445523', '0.000597484631236'),
('1.36145144269', '0.191990145954'),
('0.995115955831', '0.001737867413'),
('0.177234820211', '0.000888216974141'),
('0.32598260019', '0.00212234610321'),
('0.0407582816401', '0.0141094186006'),
('0.697626830712', '0.293862758908'),
('1.13297598517', '0.847418919793'),
('1.06084141978', '0.00256378459937'),
('3.14861908316', '0.00746054791773'),
('0.321491081311', '0.034580535529'),
('2.41543010476', '0.0100332324868'),
('0.233623330159', '0.000641391148327'),
('0.957311266119', '0.0637825227142'),
('0.458179969628', '0.00331553537174'),
('2.05074515456', '0.0189059089272'),
('1.09970142339', '0.368945869791'),
('0.71470168078', '0.00377625713555')]
logfolds = np.log2([float(y) / float(x) for (x, y) in points])
column = np.reshape(logfolds, (-1, 1))
cmap = plt.cm.RdYlBu_r
remap = True
if remap:
absvmin = abs(min(logfolds))
vmax = max(logfolds)
midpoint = absvmin / (vmax + absvmin)
cmap = remap_cmap(cmap, midpoint=midpoint)
axis = plt.gca()
axis.set_ylim((0, len(logfolds)))
axis.set_yticks(np.arange(len(logfolds)) + 0.5, minor = False)
axis.set_yticklabels(np.arange(len(logfolds)))
axis.set_xticks([])
heatmap = axis.pcolor(column, cmap=cmap)
cbar = plt.colorbar(
mappable=heatmap,
orientation="vertical",
fraction=0.1)
axis.tick_params(
axis="y", left="off", right="off",
labelsize=5)
axis.set_aspect('equal')
plt.savefig("heatmap.pdf", dpi=300, bbox_inches="tight")
Setting remap = False
avoids the error.
I'm not sure my diagnositc is correct and I'm not at all familiar with the intarnals of matplotlib, but what I observe on a particular case is the following:
When I use the
plt.cm.RdYlBu_r
colormap, the figure can be saved. When I instead run this colormap throughremappedColorMap
,plt.savefig
fails with the following error: "ValueError: data mapping points must have x in increasing order"After some investigation using the
pdb
debugger (which I use for the first time), it seems that the problem occurs atx = self.cmap(x, alpha=alpha, bytes=bytes)
at the end ofScalarMappable.to_rgba
.See the following pdb excerpt:
Notice how
[d[0] for d in self._segmentdata['red']]
has values above 1, whereas the data on whichcmap
was called (x
) seemed normal.