python - 3 subplots (2 graphs & 1 colorbar) -


i want plot figure made of 3 subplots: 2 of them normal graphs , 1 has color bar.

here images: enter image description here enter image description here

so want put images next each other (horizontally).

here code wrote generate first figure:

plt.scatter(x, y, s = 40, c=z) plt.colorbar() 

and here's code second figure:

fig, axes = plt.subplots(1, 2, sharey = true)  axes[0].plot(z, y, 'ok') axes[1].plot(x, y, 'ok') 

in order place figures horizontally next each other tried following: (but got error)

fig, axes = plt.subplots(1, 3, sharey = true) axes[0].plot(z, y, 'ok') axes[1].plot(x, y, 'ok') axes[2].scatter(x, y, s = 40, c = z) fig.colorbar() 

can tell me why getting error , how solve this?

according http://matplotlib.org/api/figure_api.html#matplotlib.figure.figure.colorbar have pass neccessary argument mappable colorbar method of figure.

import matplotlib.pyplot plt  x = [1,2,3,4] y = [1,2,1,3] z = [10, 20, 30, 40]  fig, axes = plt.subplots(1, 3, sharey = true) axes[0].plot(z, y, 'ok') axes[1].plot(x, y, 'ok') a2 = axes[2].scatter(x, y, s = 40, c=z) fig.colorbar(a2)  plt.show() 

code above works fine.

as first example, plt wise shortcut latest figure instance. far created 1 plot , 1 artist, works good.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -