← Back to NumPy Course | Chapter 12: Advanced Topics | Lesson 7 of 7

NumPy और Matplotlib के Basics

NumPy numbers बनाता है और Matplotlib इन्हें draw करता है, और दोनों लगभग हमेशा साथ इस्तेमाल होते हैं।
Syntax
python
import matplotlib.pyplot as plt
x = np.linspace(start, stop, num)
y = np.function(x)
plt.plot(x, y)
plt.show()

Matplotlib के साथ NumPy Basics

Matplotlib NumPy arrays को directly plot करता है। x values के लिए linspace और y values के लिए np.sin जैसा एक ufunc इस्तेमाल करें, फिर plt.plot call करें। नीचे, chart off-screen draw होता है और memory में save होता है ताकि आप देख सकें कि यह काम किया।

Note: एक normal script या notebook में, plot window display करने के लिए plt.show() call करें।

उदाहरण: NumPy with Matplotlib basics

python
import io
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title("Sine wave")
buf = io.BytesIO()
plt.savefig(buf, format="png")
print("points plotted:", len(x))
print("png rendered:", buf.getbuffer().nbytes > 0)

# Output:
# points plotted: 100
# png rendered: True
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. scripts में plt.show भूल जाना
  2. अलग lengths वाले arrays pass करना
  3. एक smooth curve के लिए बहुत कम points इस्तेमाल करना
चैप्टर सारांश
  • Matplotlib NumPy arrays accept करता है
  • linspace x values बनाता है
  • ufuncs y values बनाते हैं
  • plt.show figure display करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.