Search code examples
matplotlibframeaxes

add_axes with no frame


I'm trying to insert an axis inside a plot but without the frame. Somehow the options do not work at all

I have the following mwe

import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as AA

f = plt.figure()
ax = f.add_subplot(111)

iax = AA.Axes(f, [0.125, 0.125, 0.775, 0.2], frameon=False)
f.add_axes(iax, frameon=False)
iax.set_yticks([]), iax.set_xticks([])

plt.show()

Solution

  • The purpose of using matplotlib.axisartist is not clear from the question. To obtain a frameless axes you may use figure.add_axes([..], frameon=False):

    import matplotlib.pyplot as plt
    
    f = plt.figure()
    ax = f.add_subplot(111)
    
    iax = f.add_axes([0.125, 0.125, 0.775, 0.2], frameon=False)
    iax.set_yticks([]), iax.set_xticks([])
    iax.plot(range(10),[i%4 for i in range(10)])
    
    plt.show()