Skip to content

Commit

Permalink
allow custom colormaps
Browse files Browse the repository at this point in the history
  • Loading branch information
wiheto committed Nov 30, 2022
1 parent 8044464 commit 708826b
Show file tree
Hide file tree
Showing 24 changed files with 930 additions and 269 deletions.
6 changes: 5 additions & 1 deletion docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

[![](./gallery/figures/specifying_node_color.png)](./specifying_node_color/)

### [Dual row figures](.//two_rows/)
### [Specifying colormaps](./node_cmap/)

[![](./gallery/figures/node_cmap.png)](./node_cmap/)

### [Dual row figures](./two_rows/)

[![](./gallery/figures/rows1.png)](./two_rows/)

Expand Down
File renamed without changes.
Binary file added docs/gallery/figures/node_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gallery/figures/specifying_node_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 16 additions & 19 deletions docs/gallery/highlevel_size.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# %% [markdown]
"""
# Node properties: size
Netplotbrain allows for specifying different figure properties by only specifyign the column name.
Below we demonstrate how node_size can change based on different columns in the nodes dataframe.
The key lines of code here are when:
`node_size='centrality_measure1'`
and
`node_size='centrality_measure2'`
These columns could be called anything such as "module_degree_zscore" or "efficiency"
"""
#
# # Node properties: size
#
# Netplotbrain allows for specifying different figure properties by only specifyign the column name.
#
# Below we demonstrate how node_size can change based on different columns in the nodes dataframe.
#
# The key lines of code here are when:
#
# `node_size='centrality_measure1'`
#
# and
#
# `node_size='centrality_measure2'`
#
# These columns could be called anything such as "module_degree_zscore" or "efficiency"
52 changes: 31 additions & 21 deletions docs/gallery/infant.ipynb

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions docs/gallery/nbs.ipynb

Large diffs are not rendered by default.

418 changes: 418 additions & 0 deletions docs/gallery/node_cmap.ipynb

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions docs/gallery/node_cmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# # Specifying node colormaps
#
# [Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/node_cmap.ipynb)
#
# See [example about colors for different way the color columns in the dataframe can be specified](https://www.netplotbrain.org/gallery/specifying_node_color/)
#
# There are two different ways to specify colormaps. This holds for both nodes (node_cmap) edges (edge_cmap)
#
# The first way entails that you specify a matplotlib colormap (e.g. Set1, Inferno, (see options [here](https://matplotlib.org/stable/tutorials/colors/colormaps.html))
#
# The second way is to provide a list of matplotlib colors to create your own colormap (see named color options [here](https://matplotlib.org/stable/gallery/color/named_colors.html))
#
# This notebook will shows an example of each of these. We will use 100 ROIs from the Schaefer atlas and color the 7 Yeo networks

# Import necessary packages
import netplotbrain
import pandas as pd
import templateflow.api as tf

# Load templateflow information about the Schaefer atlas
atlasinfo = tf.get(template='MNI152NLin2009cAsym',
atlas='Schaefer2018',
desc='100Parcels7Networks',
extension='.tsv')
atlas_df = pd.read_csv(str(atlasinfo), sep='\t')
atlas_df.head()

# Create a column called "network" by extracting the relevant information from the column "name"
atlas_df['network'] = list(map(lambda x: x.split('_')[2], atlas_df.name.values))
atlas_df.head()

# Define the TemplateFlow parcels that we want to plot
nodes = {'template': 'MNI152NLin2009cAsym',
'atlas': 'Schaefer2018',
'desc': '100Parcels7Networks',
'resolution': 1}

# Plot with a the Set2 colormap
netplotbrain.plot(nodes=nodes,
node_type='parcels',
nodes_df=atlas_df,
node_color='network',
node_cmap='Set2')

# Create custom colormap
node_cmap = ['blue', 'red', 'green', 'black', 'purple', 'yellow', 'orange']

# Plot with a the custom colormap
netplotbrain.plot(nodes=nodes,
node_type='parcels',
nodes_df=atlas_df,
node_color='network',
node_cmap=node_cmap)
122 changes: 86 additions & 36 deletions docs/gallery/node_styles.ipynb

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions docs/gallery/simple.ipynb

Large diffs are not rendered by default.

175 changes: 141 additions & 34 deletions docs/gallery/specifying_node_color.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
"cells": [
{
"cell_type": "markdown",
"id": "00714681",
"id": "4d96e067",
"metadata": {},
"source": [
" \n",
"# Specifying node colours\n",
"\n",
"[Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/node_colors.ipynb)\n",
"[Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/specifying_node_color.ipynb)\n",
"\n",
"There are three different ways to specify different colours of nodes.\n",
"Both are done by setting node_color keyword argument.\n",
"If this column consists of category data, different categories will be plotted.\n",
"If this column consists of continuous data, a colour spectrum will be plotted. \n",
"If this column consists of differernt colours, these colours will be plotted. \n",
"\n",
"In this notebook we will see an example of each of the three different ways"
"In this notebook we will see an example of each of the three different ways.\n",
"\n",
"See [example about cmap for specifying colormaps](https://www.netplotbrain.org/gallery/node_cmap/) "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "55baafb7",
"id": "b666792b",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:22.838614Z",
"iopub.status.busy": "2022-11-28T14:48:22.837492Z",
"iopub.status.idle": "2022-11-28T14:48:25.394354Z",
"shell.execute_reply": "2022-11-28T14:48:25.393942Z"
"iopub.execute_input": "2022-11-30T20:32:31.379155Z",
"iopub.status.busy": "2022-11-30T20:32:31.378760Z",
"iopub.status.idle": "2022-11-30T20:32:34.823308Z",
"shell.execute_reply": "2022-11-30T20:32:34.822830Z"
}
},
"outputs": [],
Expand All @@ -44,13 +46,13 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "352bbd25",
"id": "2b297af0",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:25.396394Z",
"iopub.status.busy": "2022-11-28T14:48:25.396267Z",
"iopub.status.idle": "2022-11-28T14:48:25.415233Z",
"shell.execute_reply": "2022-11-28T14:48:25.414844Z"
"iopub.execute_input": "2022-11-30T20:32:34.826450Z",
"iopub.status.busy": "2022-11-30T20:32:34.825883Z",
"iopub.status.idle": "2022-11-30T20:32:34.865359Z",
"shell.execute_reply": "2022-11-30T20:32:34.864879Z"
},
"lines_to_next_cell": 2
},
Expand Down Expand Up @@ -143,13 +145,13 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "96b553e9",
"id": "13682bb7",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:25.416997Z",
"iopub.status.busy": "2022-11-28T14:48:25.416884Z",
"iopub.status.idle": "2022-11-28T14:48:25.419734Z",
"shell.execute_reply": "2022-11-28T14:48:25.419313Z"
"iopub.execute_input": "2022-11-30T20:32:34.868467Z",
"iopub.status.busy": "2022-11-30T20:32:34.867934Z",
"iopub.status.idle": "2022-11-30T20:32:34.872783Z",
"shell.execute_reply": "2022-11-30T20:32:34.872076Z"
}
},
"outputs": [],
Expand All @@ -162,13 +164,13 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "e6418347",
"id": "676456dc",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:25.421338Z",
"iopub.status.busy": "2022-11-28T14:48:25.421198Z",
"iopub.status.idle": "2022-11-28T14:48:25.423519Z",
"shell.execute_reply": "2022-11-28T14:48:25.423254Z"
"iopub.execute_input": "2022-11-30T20:32:34.876287Z",
"iopub.status.busy": "2022-11-30T20:32:34.875759Z",
"iopub.status.idle": "2022-11-30T20:32:34.879829Z",
"shell.execute_reply": "2022-11-30T20:32:34.879037Z"
}
},
"outputs": [],
Expand All @@ -180,13 +182,118 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "67dbea75",
"id": "1724e757",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:32:34.886455Z",
"iopub.status.busy": "2022-11-30T20:32:34.886091Z",
"iopub.status.idle": "2022-11-30T20:32:34.896063Z",
"shell.execute_reply": "2022-11-30T20:32:34.895530Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>index</th>\n",
" <th>name</th>\n",
" <th>color</th>\n",
" <th>network</th>\n",
" <th>centrality</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>7Networks_LH_Vis_1</td>\n",
" <td>#781283</td>\n",
" <td>Vis</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>7Networks_LH_Vis_2</td>\n",
" <td>#781284</td>\n",
" <td>Vis</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>7Networks_LH_Vis_3</td>\n",
" <td>#781285</td>\n",
" <td>Vis</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>7Networks_LH_Vis_4</td>\n",
" <td>#781287</td>\n",
" <td>Vis</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>7Networks_LH_Vis_5</td>\n",
" <td>#781288</td>\n",
" <td>Vis</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" index name color network centrality\n",
"0 1 7Networks_LH_Vis_1 #781283 Vis 0\n",
"1 2 7Networks_LH_Vis_2 #781284 Vis 1\n",
"2 3 7Networks_LH_Vis_3 #781285 Vis 2\n",
"3 4 7Networks_LH_Vis_4 #781287 Vis 3\n",
"4 5 7Networks_LH_Vis_5 #781288 Vis 4"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Lets have a look at the data frame now with three different columns for colours\n",
"atlas_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "09195103",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:25.425203Z",
"iopub.status.busy": "2022-11-28T14:48:25.425097Z",
"iopub.status.idle": "2022-11-28T14:48:25.427084Z",
"shell.execute_reply": "2022-11-28T14:48:25.426827Z"
"iopub.execute_input": "2022-11-30T20:32:34.899668Z",
"iopub.status.busy": "2022-11-30T20:32:34.899408Z",
"iopub.status.idle": "2022-11-30T20:32:34.902870Z",
"shell.execute_reply": "2022-11-30T20:32:34.902347Z"
}
},
"outputs": [],
Expand All @@ -200,14 +307,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"id": "472a8989",
"execution_count": 7,
"id": "ffab46b1",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-28T14:48:25.428727Z",
"iopub.status.busy": "2022-11-28T14:48:25.428595Z",
"iopub.status.idle": "2022-11-28T14:50:01.581763Z",
"shell.execute_reply": "2022-11-28T14:50:01.581317Z"
"iopub.execute_input": "2022-11-30T20:32:34.905177Z",
"iopub.status.busy": "2022-11-30T20:32:34.905020Z",
"iopub.status.idle": "2022-11-30T20:34:06.148065Z",
"shell.execute_reply": "2022-11-30T20:34:06.147715Z"
}
},
"outputs": [
Expand Down
9 changes: 7 additions & 2 deletions docs/gallery/specifying_node_color.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#
# # Specifying node colours
#
# [Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/node_colors.ipynb)
# [Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/specifying_node_color.ipynb)
#
# There are three different ways to specify different colours of nodes.
# Both are done by setting node_color keyword argument.
# If this column consists of category data, different categories will be plotted.
# If this column consists of continuous data, a colour spectrum will be plotted.
# If this column consists of differernt colours, these colours will be plotted.
#
# In this notebook we will see an example of each of the three different ways
# In this notebook we will see an example of each of the three different ways.
#
# See [example about cmap for specifying colormaps](https://www.netplotbrain.org/gallery/node_cmap/)

# Import packages
import templateflow.api as tf
Expand All @@ -34,6 +36,9 @@
# Add a continuous variable between 0-10
atlas_df['centrality'] = np.tile(np.arange(0,10), 10)

# Lets have a look at the data frame now with three different columns for colours
atlas_df.head()

# define the nodes as templateflow dict
nodes = {'template': 'MNI152NLin2009cAsym',
'atlas': 'Schaefer2018',
Expand Down
Loading

0 comments on commit 708826b

Please sign in to comment.