1

I need a figure without labels, axes, and frame - just the pure data plot.

For example:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_facecolor('green')
ax.plot(range(0, 10), c='red')

creates this plot

enter image description here

The problems:

  1. Option removes the ticks and labels but a small black frame remains.

     ax.xaxis.set_visible(False)
     ax.yaxis.set_visible(False)
    
  2. Option removes the background and still leaves a white margin.

     ax.axis('off') 
     fig.tight_layout(pad=0)
    
  3. Option removes everything I want but also the background:

     fig.patch.set_visible(False)
    

Other solutions like this one don't work as well.

Any ideas?

Michael Dorner
  • 17,587
  • 13
  • 87
  • 117

1 Answers1

2

You can remove the white margins with subplots_adjust and the frame with spines.set_visible:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_facecolor('green')
ax.plot(range(0, 10), c='red')

plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)

plt.show()

Output:

enter image description here

Tranbi
  • 11,407
  • 6
  • 16
  • 33