Skip to content

Commit

Permalink
Merge pull request #90 from BranniganLab/22-get_cmap-is-deprecated-in…
Browse files Browse the repository at this point in the history
…-matplotlib

22 get cmap is deprecated in matplotlib
  • Loading branch information
EzryStIago authored Nov 14, 2024
2 parents 53b4085 + 3aa3b83 commit 04c271e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
29 changes: 29 additions & 0 deletions python/plotting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 11 14:41:24 2024.
@author: js2746
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap


def make_custom_colormap():
"""
Make a custom colormap for plotting. The colormap starts at 0.35 to ensure \
that there is a visual difference between 0 (no signal) and depleted (near-\
zero enrichment).
Returns
-------
my_cmap : matplotlib colormap
The colormap to use when plotting.
"""
depleted = plt.colormaps['RdGy_r']
enriched = plt.colormaps['bwr']
newcolors = np.concatenate([depleted(np.linspace(0.35, 0.5, 128)), enriched(np.linspace(0.5, 1, 128))])
my_cmap = ListedColormap(newcolors)
return my_cmap
20 changes: 4 additions & 16 deletions python/preliminaries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@
"from DTA.enrichment_plotters import polar_plot, get_file_list, get_helices, read_rep\n",
"from DTA.polarDensity_helper import Coord_Get, get_header_info\n",
"from DTA.site_distributions import outline_site, make_symmetric_sites, combine_sites, plot_density, Site\n",
"from plotting import make_custom_colormap\n",
"my_cmap = make_custom_colormap()\n",
"plt.rcParams['axes.grid'] = False "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Enrichment plot colormap\n",
"from matplotlib.colors import ListedColormap\n",
"depleted = plt.cm.get_cmap('RdGy_r', 256)\n",
"enriched = plt.cm.get_cmap('bwr', 256)\n",
"newcolors = np.concatenate([depleted(np.linspace(0.35, 0.5, 128)), enriched(np.linspace(0.5,1,128))])\n",
"my_cmap = ListedColormap(newcolors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -382,7 +370,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "jupEnv",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -396,7 +384,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 04c271e

Please sign in to comment.