diff --git a/python/plotting.py b/python/plotting.py new file mode 100644 index 0000000..822f040 --- /dev/null +++ b/python/plotting.py @@ -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 diff --git a/python/preliminaries.ipynb b/python/preliminaries.ipynb index d19ed38..250bcb3 100644 --- a/python/preliminaries.ipynb +++ b/python/preliminaries.ipynb @@ -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": {}, @@ -382,7 +370,7 @@ ], "metadata": { "kernelspec": { - "display_name": "jupEnv", + "display_name": "base", "language": "python", "name": "python3" }, @@ -396,7 +384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.11.5" } }, "nbformat": 4,