nipy / PySurfer

Cortical neuroimaging visualization in Python
https://pysurfer.github.io/
BSD 3-Clause "New" or "Revised" License
239 stars 98 forks source link

Change color of add_contour_overlay function #231

Closed ZaixuCui closed 6 years ago

ZaixuCui commented 6 years ago

Hi there,

I am trying to use function add_contour_overlay function to plot the contour of several ROIs. I wonder how to change the contour colour with a specific RGB, for example, 175 51 173. I am following the example https://pysurfer.github.io/auto_examples/plot_freesurfer_normalization.html#sphx-glr-auto-examples-plot-freesurfer-normalization-py. I thought I should change the option parameter 'colormap', but I can only change colour with matplotlib colormap string. How to specify a colour with RGB=[175 51 173].

Thank you so much.

Best

Zaixu

mwaskom commented 6 years ago

According to the api docs you can specify the color in a number of ways:

colormap : string, list of colors, or array

name of matplotlib colormap to use, a list of matplotlib colors, or a custom look up table (an n x 4 array coded with RBGA values between 0 and 255).

ZaixuCui commented 6 years ago

Thank you so much for the quick reply. I have noticed that. For this example (https://pysurfer.github.io/auto_examples/plot_freesurfer_normalization.html#sphx-glr-auto-examples-plot-freesurfer-normalization-py), I used the following commands and successfully changed the color.

import numpy as np z=np.zeros((len(curv_bin),4)) indice=np.where(curv_bin) indice=indice[0] for i in np.arange(len(indice)): z[indice[i],]=[175, 51, 173, 255]; brain.add_contour_overlay(curv_bin, min=0, max=1.5, n_contours=2, line_width=3, hemi='rh', colormap=z)

But this is super complex. I just want the contour with the same color RGB=[175, 51, 173]. But here, I have to construct a big array to do this, it's a 163842*4 array.

ZaixuCui commented 6 years ago

I mean, is there any simple way to do this? Thank you so much.

mwaskom commented 6 years ago

Try colormap=[(175, 51, 173)].

ZaixuCui commented 6 years ago

Wow, Awesome. It does work. But the value should in within 0~1. So, colormap = [(175./255, 51./255, 173./255)]

Than you so much for your help.

mwaskom commented 6 years ago

Ah yes there's an annoying inconsistency in what scales are expected for lists vs. array inputs (because matplotlib and mayavi have different expectations). I never remember which is which but it's probably been around too long to "fix" without breaking a lot of existing code...

Glad it works.