Open wingedRuslan opened 5 years ago
create subplot for the brain plotting
fig, ax = plt.subplots(figsize=(9,12))
# And then loop through each node and add it in order
for node in node_order:
aaa = nx.draw_networkx_nodes(H, # A networkx graph
pos=pos, # A dict with nodes as keys and positions as values.
node_color=colors_list[node], # color for each node
nodelist=[node], # Draw only this one node
ax=ax)
nx.draw_networkx_edges(G2, # plotting for thresholded edges G2
pos=pos,
edgelist=edge_list_G2,
edge_color = "lightgrey",
ax=ax)
add subplot - basically adds an Axes to the figure as part of a subplot arrangement.
ax2 = fig.add_subplot(15, 1, 15, xticklabels=[], yticklabels=[])
vmin = min(nodal_measures[measure].values)
vmax = max(nodal_measures[measure].values)
norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
# ticks = [round(vmin,2), round((vmin+vmax)/2,2), round(vmax,2)]
ticks = [vmin, (vmin+vmax)/2, vmax]
cb = mpl.colorbar.ColorbarBase(ax2, cmap="hot_r",
norm=norm,
ticks=ticks,
format='%.2f',
orientation='horizontal')
cb.set_label(measure, size=20)
ax2.tick_params(labelsize=20)
plt.tight_layout()
plt.subplots_adjust(top=1)
sns.despine(top=True, right=True, left=True, bottom=True)
fig.savefig("CCC", bbox_inches=0, dpi=100)
Try adding a grid. Subplots are really hard to adjust and control if you go outside of what they’re designed to do (which is have multiple similar sized plots).
Here’s some code on setting up a grid rather than a subplot: https://github.com/WhitakerLab/scona/blob/1e70f46ec3f5ebc595cb75837bb5ea235ec2b149/scona/scripts/make_figures.py#L1890
Hi @KirstieJane,
I tried different things to make space below the colorbar but without any positive results :( image
Now to draw colorbar, we need create a new axes and create colobar on this axes
1) Increase the size of the figure. Even though it is not a good solution, it does not work. It simply makes the figure with bigger height (no space at the bottom added) 2) plt.tight_layout() - shows warning that it can not be applied to the new axes (still no space) /home/pilot/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py:1999: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. warnings.warn("This figure includes Axes that are not compatible "
3) plt.subplots_adjust(bottom=0.2) - this "lifts up" the main plot, but not the colorbar (so the space between the main plot and colorbar increases) 4) axes.margins() - does not change anything
I might miss something obvious though...
Without adding spacing below, it does not make sense to commit, right?