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

Colormap in topoplot #109

Open
jgcordoba opened this issue Sep 16, 2022 · 1 comment
Open

Colormap in topoplot #109

jgcordoba opened this issue Sep 16, 2022 · 1 comment

Comments

@jgcordoba
Copy link

jgcordoba commented Sep 16, 2022

Hi to everyone!

When I try to create a colormap or make a discrete colormap from an existing one from matplotlib and apply it to the topoplot function, I get an error. I would like to know if this is possible or if there is not this functionality of using a different colormap than the original ones from matplotlib.

This is my script:

import numpy as np
from visbrain.objects import TopoObj, ColorbarObj, SceneObj
import matplotlib as plt

def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""

# Note that if base_cmap is a string or None, you can simply do
#    return plt.cm.get_cmap(base_cmap, N)
# The following works for string, None, or a colormap instance:

base = plt.cm.get_cmap(base_cmap)
color_list = base(np.linspace(0, 1, N))
cmap_name = base.name
return base.from_list(cmap_name, color_list, N)

m_data = np.array([210.55324061, 286.12320408, 158.11973237, 185.29573764,
193.14262184, 187.81332827, 218.20972376, 224.45368389])

kw_top = dict(margin=30 / 100, chan_offset=(0.1, 0.1, 0.), chan_size=10, cmap=discrete_cmap(5,'summer'))
kw_cbar = dict(cbtxtsz=12, txtsz=10., width=.3, txtcolor='black', cbtxtsh=1.8,
rect=(0., -2., 1., 4.), border=True)
kw_title = dict(title_color='black', title_size=11.0, width_max=300)

sc = SceneObj(bgcolor='white' )

ch_names = ['Fp1', 'Fp2', 'T3', 'T4', 'C3', 'C4', 'O1', 'O2']

Create the topoplot and the associated colorbar

t_obj = TopoObj('topo', m_data, channels=ch_names, **kw_top)
cb_obj1 = ColorbarObj(t_obj, cblabel='Colorbar label', **kw_cbar)
sc.add_to_subplot(cb_obj1, row=0, col=1, row_span=1, width_max=50)
sc.add_to_subplot(t_obj, row=0, col=0, title='Example', **kw_title)
sc.preview()

@EtienneCmb
Copy link
Owner

Hi @jgcordoba,

I'm don't think it is currently possible to create a discret colormap, but you can probably use an existing one (like set, set2 etc.)

Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants