|
3 | 3 |
|
4 | 4 | importmatplotlibasmpl
|
5 | 5 | importmatplotlib.pyplotasplt
|
| 6 | +importmatplotlib.tickerasmticker |
6 | 7 | frommatplotlibimportcbook
|
7 | 8 | frommatplotlib.backend_basesimportMouseEvent
|
8 | 9 | frommatplotlib.colorsimportLogNorm
|
@@ -568,3 +569,52 @@ def test_rgb_axes():
|
568 | 569 | g=rng.random((5,5))
|
569 | 570 | b=rng.random((5,5))
|
570 | 571 | ax.imshow_rgb(r,g,b,interpolation='none')
|
| 572 | + |
| 573 | + |
| 574 | +# The original version of this test relied on mpl_toolkits's slightly different |
| 575 | +# colorbar implementation; moving to matplotlib's own colorbar implementation |
| 576 | +# caused the small image comparison error. |
| 577 | +@image_comparison(['imagegrid_cbar_mode.png'], |
| 578 | +remove_text=True,style='mpl20',tol=0.3) |
| 579 | +deftest_imagegrid_cbar_mode_edge(): |
| 580 | +# Remove this line when this test image is regenerated. |
| 581 | +plt.rcParams['pcolormesh.snap']=False |
| 582 | + |
| 583 | +X,Y=np.meshgrid(np.linspace(0,6,30),np.linspace(0,6,30)) |
| 584 | +arr=np.sin(X)*np.cos(Y)+1j*(np.sin(3*Y)*np.cos(Y/2.)) |
| 585 | + |
| 586 | +fig=plt.figure(figsize=(18,9)) |
| 587 | + |
| 588 | +positions= (241,242,243,244,245,246,247,248) |
| 589 | +directions= ['row']*4+ ['column']*4 |
| 590 | +cbar_locations= ['left','right','top','bottom']*2 |
| 591 | + |
| 592 | +forposition,direction,locationinzip( |
| 593 | +positions,directions,cbar_locations): |
| 594 | +grid=ImageGrid(fig,position, |
| 595 | +nrows_ncols=(2,2), |
| 596 | +direction=direction, |
| 597 | +cbar_location=location, |
| 598 | +cbar_size='20%', |
| 599 | +cbar_mode='edge') |
| 600 | +ax1,ax2,ax3,ax4,=grid |
| 601 | + |
| 602 | +ax1.imshow(arr.real,cmap='nipy_spectral') |
| 603 | +ax2.imshow(arr.imag,cmap='hot') |
| 604 | +ax3.imshow(np.abs(arr),cmap='jet') |
| 605 | +ax4.imshow(np.arctan2(arr.imag,arr.real),cmap='hsv') |
| 606 | + |
| 607 | +# In each row/column, the "first" colorbars must be overwritten by the |
| 608 | +# "second" ones. To achieve this, clear out the axes first. |
| 609 | +foraxingrid: |
| 610 | +ax.cax.cla() |
| 611 | +cb=ax.cax.colorbar(ax.images[0]) |
| 612 | + |
| 613 | + |
| 614 | +deftest_imagegrid(): |
| 615 | +fig=plt.figure() |
| 616 | +grid=ImageGrid(fig,111,nrows_ncols=(1,1)) |
| 617 | +ax=grid[0] |
| 618 | +im=ax.imshow([[1,2]],norm=mpl.colors.LogNorm()) |
| 619 | +cb=ax.cax.colorbar(im) |
| 620 | +assertisinstance(cb.locator,mticker.LogLocator) |