Matplotlib - two different color cards with different ranges

I am trying to combine two shapes that were separated before. One of them is a 3-panel shape (ax1, ax2, ax3) (all generated using imshow), where I used one color combination on the side. Now I want to add another shape (ax0), which I load from a png file using imreadand get_sample_data(from matplotlib.cbook).

The problem is that this new number takes the same color set as one of the three panels, which gives one simple uniform color in the newly added panel. 3 other panels still have the correct color.

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np

g1 = gridspec.GridSpec(4, 1, height_ratios=[4,1,1,1])
g1.update(wspace=0.05, hspace=0.2) # set the spacing between axes.

f, ((ax0), (ax1), (ax2), (ax3)) = plt.subplots(4, 1, sharex='col', sharey='row')

ax0 = subplot(g1[0])
ax1 = subplot(g1[1])
ax2 = subplot(g1[2])
ax3 = subplot(g1[3])

from matplotlib.cbook import get_sample_data
im2 = plt.imread(get_sample_data('PathToFig/Figure.png'))
ax0.imshow(im2, vmax=1)

ziAA = np.random.rand(4, 4, 4)
ziAB = np.random.rand(4, 4, 4)
ziBA = np.random.rand(4, 4, 4)

ax1.imshow(ziAA,origin="lower",vmin=0,vmax=0.03,aspect="auto",extent=[-0.15,0.15,0,4])
ax2.imshow(ziAB,origin="lower",vmin=0,vmax=0.03,aspect="auto",extent=[-0.15,0.15,0,4])
im = ax3.imshow(ziBA,origin="lower",vmin=0,vmax=0.03,aspect="auto",extent=[-0.15,0.15,0,4])

from matplotlib import ticker
tick_locator = ticker.MaxNLocator(nbins=5)

f.subplots_adjust(right=0.85)

cbar_ax = f.add_axes([1.0, 0.15, 0.01, 0.7])
cbar = f.colorbar(im, cax=cbar_ax)

cbar.locator = tick_locator
cbar.update_ticks()
cbar.solids.set_rasterized(True)
cbar.solids.set_edgecolor("face")

ziAB, ziBAand ziAAwere created in a previous griddatainterpolation call.

imshow, vmax. ...

ax0 ax1 - 3, ax0, , ax1 - 3.

( imshow matplotlib), , png ax0, , .

:

:

ziAA = np.random.rand(4, 4, 4)
ziAB = np.random.rand(4, 4, 4)
ziBA = np.random.rand(4, 4, 4)

png:

Toy image

. . , , vmin, vmax , , , png. , -, png...

+4
1

im0 = ax0.imshow(im2, aspect='auto',extent=[-0.15,0.15,0,4])

:

enter image description here

+1

Source: https://habr.com/ru/post/1618677/


All Articles