Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, figure.colorbar() is good for both images, as long as their are not with too different scales. So you could let matplotlib do it for you... or you manually position your colorbar on axes inside the images. Here is how to control the location of the colorbar:</p> <pre><code>import numpy as np from matplotlib import pyplot as plt A = np.random.random_integers(0, 10, 100).reshape(10, 10) B = np.random.random_integers(0, 10, 100).reshape(10, 10) fig = plt.figure() ax1 = fig.add_subplot(221) ax2 = fig.add_subplot(222) mapable = ax1.imshow(A, interpolation="nearest") cax = ax2.imshow(A, interpolation="nearest") # set the tickmarks *if* you want cutom (ie, arbitrary) tick labels: cbar = fig.colorbar(cax, ax=None) fig = plt.figure(2) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) mapable = ax1.imshow(A, interpolation="nearest") cax = ax2.imshow(A, interpolation="nearest") # on the figure total in precent l b w , height ax3 = fig.add_axes([0.1, 0.1, 0.8, 0.05]) # setup colorbar axes. # put the colorbar on new axes cbar = fig.colorbar(mapable,cax=ax3,orientation='horizontal') plt.show() </code></pre> <p>Note ofcourse you can position ax3 as you wish, on the side, on the top, where ever, as long as it is in the boundaries of the figure. </p> <p>I don't know why your line2D is not appearing. </p> <p>I added to my code before plt.show() the following and everything is showing:</p> <pre><code>from mpl_toolkits.axes_grid1 import anchored_artists from matplotlib.patheffects import withStroke txt = anchored_artists.AnchoredText("SC", loc=2, frameon=False, prop=dict(size=12)) if withStroke: txt.txt._text.set_path_effects([withStroke(foreground="w", linewidth=3)]) ax1.add_artist(txt) ## Draw a line to separate the two different wave lengths, and name each region l1 = plt.Line2D([-1,10],[5,5],ls='-',color='black',lineswidth=10) ax1.add_line(l1) </code></pre> <p><img src="https://i.stack.imgur.com/x4IhX.png" alt="Color bar on axes"> <img src="https://i.stack.imgur.com/TGw3T.png" alt="WithLine"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload