Closed monchin closed 6 years ago
Unfortunately we do not support adding a color bar along side your graph, however you can use matplotlib to write a stand-alone color bar in the cell following your graph. For example, the following code will create a color bar given you know your highest and lowest node values.
import matplotlib.pyplot as plt
import matplotlib as mpl
def draw_legend(vmin, vmax, cmap = mpl.cm.bwr, label = 'Legend'):
# Make a figure and axes with dimensions as desired.
fig = plt.figure(figsize=(8, 3))
ax = fig.add_axes([0.05, 0.80, 0.9, 0.15])
# Set the colormap and norm to correspond to vmin and vmax of your original graph
norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
norm=norm,
orientation='horizontal')
# write label/units below color map
cb1.set_label(label)
draw_legend(vmin = -5, vmax = 5, cmap = mpl.cm.bwr, label = 'Legend')
Thank you for your reply! I'm wondering if I can add a visJS2jupyter object to a subplot of a plt.figure so that I can use mpl to draw colorbar, but it seems a little difficult...
As the colors represent the value of each node, I'd like to add a colorbar. So is there any way to do this?