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

22 get cmap is deprecated in matplotlib #90

Merged
merged 3 commits into from
Nov 14, 2024
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
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
@@ -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,