How to stop `colorbar` from reshaping `networkx` plot? (Python 3)
<p>I am trying to change the <code>colorbar</code> on my <code>networkx</code> plot.  The bar gets extra wide and also smooshes my original <code>networkx</code> plot (left) when I add the <code>colorbar</code> on there (right). </p>

<p><strong>How can I make my <code>colorbar</code> thinner and not alter my original <code>networkx</code> graph?</strong> </p>

<p>My code below with <code>colorbar</code> courtesy of <a href="http://stackoverflow.com/users/5285918/lanery">http://stackoverflow.com/users/5285918/lanery</a> but used w/ a larger network. </p>

<pre><code># Set up Graph
DF_adj = pd.DataFrame(np.array(
     [[1, 0, 1, 1],
     [0, 1, 1, 0],
     [1, 1, 1, 1],
     [1, 0, 1, 1] ]), columns=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'], index=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'])

G = nx.Graph(DF_adj.as_matrix())
G = nx.relabel_nodes(G, dict(zip(range(4), ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'])))

# Color mapping
color_palette = sns.cubehelix_palette(3)
cmap = {k:color_palette[v-1] for k,v in zip(['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'],[2, 1, 3, 2])}

# Draw
fig, ax = plt.subplots()
nx.draw(G, node_color=[cmap[node] for node in G.nodes()], with_labels=True, ax=ax)

sm = plt.cm.ScalarMappable(cmap=ListedColormap(color_palette),
                           norm=plt.Normalize(vmin=0, vmax=3))
sm._A = []
fig.colorbar(sm, ticks=range(1,4))
</code></pre>

<p><a href="http://i.stack.imgur.com/g3vG8.png" rel="nofollow"><img src="http://i.stack.imgur.com/g3vG8.png" alt="enter image description here"></a></p>

<p>Easiest way should be to plot the colorbar on its own axis and play around with the [left, bottom, width, height] parameters.</p>

<pre><code>cbaxes = fig.add_axes([0.9, 0.1, 0.015, 0.8])
sm = plt.cm.ScalarMappable(cmap=ListedColormap(color_palette),
                           norm=plt.Normalize(vmin=0, vmax=3))
sm._A = []
plt.colorbar(sm, cax=cbaxes, ticks=range(4))
</code></pre>

<p>Source: <a href="http://stackoverflow.com/questions/13310594/positioning-the-colorbar">positioning the colorbar</a></p>

python matplotlib colors networkx colorbar