प्लॉट एरिया के बाहर एनोटेशन रखने के लिए annotate() में xycoords=ax.get_xaxis_transform() का उपयोग करें।
चरण
- फिगर साइज़ और ऑटोलेआउट सेट करें।
- रैंडम स्कैटर डेटा जनरेट करें।
fig, ax = plt.subplots()औरax.scatter()से प्लॉट करें।ax.annotate()मेंxy=(0.30, 1.05)औरxycoords=ax.get_xaxis_transform()से बाहर टेक्स्ट रखें।plt.show()से दिखाएं।
उदाहरण कोड
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.rand(100)
y = np.random.rand(100)
fig, ax = plt.subplots()
ax.scatter(x, y, c=y, marker="*", cmap="copper")
ax.annotate('Scatter points (outside the drawing)', xy=(0.30, 1.05), xycoords=ax.get_xaxis_transform())
plt.show()
आउटपुट
स्कैटर प्लॉट के ऊपर (एक्सिस के बाहर) "Scatter points (outside the drawing)" टेक्स्ट।