1

I have the following code:

fig, ax = plt.subplots()
fig.set_size_inches(10, 10, forward=True)
min_val, max_val = 0, 28

inputBild = np.round(np.reshape(inputBild, [28, 28]), 1)
plt.imshow(inputBild)

for i in range(28):
    for j in range(28):
        c = inputBild[j,i]
        ax.text(i, j, str(c), va='center', ha='center')
ax.set_facecolor((1.0, 0.47, 0.42))
plt.savefig('/tmp/inputMitZahlOhneCmap.png', bbox_inches='tight')

inputBild is a random image of the mnist dataset.

I want to only plot the numbers but not the colormap. How can I remove it if I didn't even specify one?

  • What happens if you comment the line `plt.imshow(inputBild)`? By colormap you mean the color on the graph? – xdze2 Sep 02 '18 at 20:07
  • Currently it's completely unclear what your dataset is, how does the desired output image looks like. Be more specific. What is `inputBild`? – Sheldore Sep 02 '18 at 20:31
  • A colormap maps numerical values to a pixel color. This means, technically you cannot show any image without a colormap. But I suppose this questions asks for mapping the values to greyscale colors instead of RGB colors. This would be shown e.g. in [this question](https://stackoverflow.com/questions/3823752/display-image-as-grayscale-using-matplotlib). I.e. you may use any of "Greys", "gray", "gist_gray", "gist_yarg" or "binary" as colormap. Example: `plt.imshow(inputBild, cmap="Greys")` – ImportanceOfBeingErnest Sep 02 '18 at 21:16
  • Im trying to just plot the numbers as strings onto my Matrix. I'm not trying to make it colored for each value. In @Bazingaa 's answer it is plotted as the colors, but I want to have no colors but just the raw numbers. And I don't have nor do I want a colorbar My inputBild is just a vector of the MNIST-Dataset. –  Sep 04 '18 at 18:26

1 Answers1

0

I am not sure if you want a scatter plot when you say "only plot the numbers" but looking at your usage of imshow, I think you want to hide the colorbar. Here is an example:

With color bar

import matplotlib.pyplot as plt 
import numpy as np
fig = plt.figure() 
ax = fig.add_subplot(111) 
data = np.random.rand(100, 100) 
cax = ax.imshow(data) 
cbar = plt.colorbar(cax) # This line includes the color bar

enter image description here

Without color bar

import matplotlib.pyplot as plt 
import numpy as np
fig = plt.figure() 
ax = fig.add_subplot(111) 
data = np.random.rand(100, 100) 
cax = ax.imshow(data) 

enter image description here

Deleting color bar: Method 1 (not showing initial lines of code)

data = np.random.rand(100, 100) 
cax = ax.imshow(data) 
cbar = plt.colorbar(cax) 
cbar.remove()

Deleting color bar: Method 2 (not showing initial lines of code)

data = np.random.rand(100, 100) 
cax = ax.imshow(data) 
plt.colorbar(cax) 
plt.delaxes(fig.axes[1]) # axes[0] correspond to the main plot.

Output Method 1 and 2

enter image description here

Sheldore
  • 32,099
  • 6
  • 34
  • 53