QuentinL
QuentinL

Reputation: 57

Superimpose independent plots in python

I want to work with only one figure, with multiples, different and modifiable plots, whithout the subplots formalism.

Is there a way to superimpose two differents plots, in the same way as text boxes, i.e anywhere on the figure ?

Here a "gimp made" example :

random graphs to show what I expect

Thanks !

Upvotes: 0

Views: 522

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339230

You can use figure.add_axes to place an axes at an arbitrary location.

fig = plt.figure()
fig.add_axes([0.1,0.2,0.3,0.4])

places an axes at x=0.1, y=0.2, width=0.3, height=0.4 in figure coordinates.

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

ax = fig.add_axes([0.4,0.1,0.5,0.6], projection='3d')
X, Y = np.meshgrid(np.arange(-5, 5, 0.25), np.arange(-5, 5, 0.25))
Z = np.sin(np.sqrt(X**2 + Y**2))
surf = ax.plot_surface(X, Y, Z, cmap="plasma")

ax = fig.add_axes([0.3,0.4,0.3,.4])
plt.plot([1,2,3])

plt.show()

enter image description here

Upvotes: 1

Related Questions