Edit: I put in the required dataframe so that the issue is reproducible.
Sorry for the long excerpt of code, this is what I have on jupyter.
You can scroll to the very bottom and look for draw_plots()
which works fine, and draws a matrix of hist2d
s.
Later as you can see I run modify_color('Hc', 'q', 0, 30)
, that also works fine and modifies the corresponding plot and its colormap update with the new limits given (0-30)
.
Problem is: the last line, when I try to run modify_color
through interactive widgets, it appears to run fine, I get good print statements which I put for debugging, but the plot and the colorbar do not update.
How can I get the plot and its colorbar to update?
merged =pd.DataFrame( {'Hc': {10000: 45.0,
10001: 68.0,
10002: 70.0,
10003: 58.0,
10004: 40.0,
10005: 40.0,
10006: 51.0,
10007: 70.0,
10008: 69.0,
10009: 70.0},
'SONUCNO': {10000: 1.0,
10001: 2.0,
10002: 3.0,
10003: 4.0,
10004: 5.0,
10005: 6.0,
10006: 7.0,
10007: 8.0,
10008: 9.0,
10009: 10.0},
'SONUCNORM': {10000: 0.07692307692307693,
10001: 0.15384615384615385,
10002: 0.2307692307692308,
10003: 0.3076923076923077,
10004: 0.38461538461538464,
10005: 0.4615384615384616,
10006: 0.5384615384615384,
10007: 0.6153846153846154,
10008: 0.6923076923076923,
10009: 0.7692307692307693},
'n_HJPair': {10000: 3,
10001: 0,
10002: 2,
10003: 0,
10004: 4,
10005: 0,
10006: 0,
10007: 2,
10008: 0,
10009: 0},
'q': {10000: 0.029980572858854998,
10001: 0.13087877831873412,
10002: 0.13350577945847913,
10003: 0.1865475118001965,
10004: 0.2053608670014144,
10005: 0.24318638969823925,
10006: 0.3040225082331678,
10007: 0.459925865474959,
10008: 0.5381321066914233,
10009: 0.5919278296001834}})
from ipywidgets import interact
inp = ['Hc', 'n_HJPair']
out = ['SONUCNO', 'SONUCNORM', 'q']
global axs
global h2d
def draw_plots(in_props=inp, out_props=out):
global axs
global h2d
n_in = len(in_props)
n_out = len(out_props)
h2d={}
%matplotlib inline
plt.rcParams['figure.figsize'] = [10*n_out, 5*n_in]
fig, axs = plt.subplots(nrows=n_in,ncols=n_out)
for index,inprop in enumerate(in_props):
for index_2, outprop in enumerate(out_props):
mask = (~((merged[inprop].isna()) | (merged[outprop].isna())))
v_max = mask.sum()/40/20*5
h2d[inprop+outprop] = (axs[index, index_2].hist2d(merged[mask][inprop],merged[mask][outprop], vmin=00, vmax=v_max, bins=[45,15], cmap='gist_rainbow'))
axs[index, index_2].set_xlabel(inprop)
axs[index, index_2].set_ylabel(outprop)
fig.colorbar(h2d[inprop+outprop][3], ax=axs[index, index_2])
draw_plots()
def modify_color(ip,op,min=0,max=0):
global h2d
print("I am running with: ",ip,op,min,max)
h2d[ip+op][3].set_clim(min,max)
modify_color('Hc', 'q', 0, 30)
interact(modify_color, ip=inp,op=out,min=0.0,max=100.0)