How can I draw a log-normalized imshow plot with a colorbar representing raw the raw data

Yes, there is! Use LogNorm. Here is a code excerpt from a utility that I wrote to display confusion matrices on a log scale. from pylab import figure, cm from matplotlib.colors import LogNorm # C = some matrix f = figure(figsize=(6.2, 5.6)) ax = f.add_axes([0.17, 0.02, 0.72, 0.79]) axcolor = f.add_axes([0.90, 0.02, 0.03, 0.79]) im … Read more

Display image as grayscale

The following code will load an image from a file image.png and will display it as grayscale. import numpy as np import matplotlib.pyplot as plt from PIL import Image fname=”image.png” image = Image.open(fname).convert(“L”) arr = np.asarray(image) plt.imshow(arr, cmap=’gray’, vmin=0, vmax=255) plt.show() If you want to display the inverse grayscale, switch the cmap to cmap=’gray_r’.

Display multiple images in subplots

To display the multiple images use subplot() plt.figure() #subplot(r,c) provide the no. of rows and columns f, axarr = plt.subplots(4,1) # use the created array to output your multiple images. In this case I have stacked 4 images vertically axarr[0].imshow(v_slice[0]) axarr[1].imshow(v_slice[1]) axarr[2].imshow(v_slice[2]) axarr[3].imshow(v_slice[3])

How to display multiple images in one figure [duplicate]

Here is my approach that you may try: import numpy as np import matplotlib.pyplot as plt w = 10 h = 10 fig = plt.figure(figsize=(8, 8)) columns = 4 rows = 5 for i in range(1, columns*rows +1): img = np.random.randint(10, size=(h,w)) fig.add_subplot(rows, columns, i) plt.imshow(img) plt.show() The resulting image: (Original answer date: Oct 7 … Read more

How to display an image

If you are using matplotlib and want to show the image in your interactive notebook, try the following: %matplotlib inline import matplotlib.pyplot as plt import matplotlib.image as mpimg img = mpimg.imread(‘your_image.png’) imgplot = plt.imshow(img) plt.show()

Adjusting gridlines and ticks in matplotlib imshow

Code for solution as suggested by Serenity: plt.figure() im = plt.imshow(np.reshape(np.random.rand(100), newshape=(10,10)), interpolation=’none’, vmin=0, vmax=1, aspect=”equal”) ax = plt.gca(); # Major ticks ax.set_xticks(np.arange(0, 10, 1)) ax.set_yticks(np.arange(0, 10, 1)) # Labels for major ticks ax.set_xticklabels(np.arange(1, 11, 1)) ax.set_yticklabels(np.arange(1, 11, 1)) # Minor ticks ax.set_xticks(np.arange(-.5, 10, 1), minor=True) ax.set_yticks(np.arange(-.5, 10, 1), minor=True) # Gridlines based on minor … Read more