Line chart: concept of line plot - plot(), set_title(), legend()

एक line chart एक ordered axis के साथ values जोड़कर एक trend दिखाता है, plt.plot() इसे खींचता है, और कई labelled lines plus legend() एक chart को एक comparison में बदल देते हैं।

8 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

तीन tests, एक चिंताजनक फुसफुसाहट

DBMS faculty फुसफुसाती है: "मुझे लगता है class slip कर रही है।"

ResultDesk के पास receipts हैं: तीन internal tests में class averages: 62, 58, 51।

एक क़तार में तीन numbers पहले से story का इशारा देते हैं, पर इसे पाँच subjects और हर एक में तीन tests तक scale कीजिए, और table धुँधली हो जाती है। आँख जो चाहती है वह है यात्रा की direction: rising, falling, flat। यही ठीक एक chart का पूरा काम है: line chart।

Theory

Dots जोड़िए, slope पढ़िए

तीन test averages को graph paper पर mark कीजिए और उन्हें बाएँ से दाएँ जोड़िए। जो line आपने खींची वही analysis है:

  • नीचे ढलती हुई: फुसफुसाहट सही थी, class slip कर रही है।
  • Steepness बताती है कितनी तेज़ी से।
  • अचानक एक kink बताता है उन दो tests के बीच कुछ हुआ।

एक line chart एक connect-the-dots है जहाँ dots का एक natural order है, और slope बात करता है।

Theory

Line chart, formally

plt.plot(x, y) लगातार (x, y) points को line segments से जोड़ता है।

इसे तब इस्तेमाल कीजिए जब x का एक natural order हो: test numbers, months, years। Connecting line दावा करती है "इन points के बीच का सफ़र meaningful है": test 1 → test 2 के लिए सच, student 101 → student 102 के लिए झूठ (पिछले lesson का zigzag)।

Useful dress-up: marker='o' line पर असली data points दिखाता है, linestyle='--' dashed reference के लिए, color= colours control करने के लिए।

Practical

दो subjects, तीन tests, एक verdict

import matplotlib.pyplot as plt

tests = [1, 2, 3]
dbms_avg  = [62, 58, 51]
maths_avg = [65, 66, 68]

plt.plot(tests, dbms_avg,  marker='o', label='DBMS')
plt.plot(tests, maths_avg, marker='o', label='Maths')

plt.title('Class average across internal tests')
plt.xlabel('Internal test')
plt.ylabel('Average score')
plt.legend()          # keys the two lines by their label=
plt.show()

# The picture: Maths gently rising, DBMS falling test by test.
# One chart replaced the whisper with evidence.

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Quiz

आपको दिखाना है semesters 1 से 4 तक एक student के total marks कैसे बदले। कौन सा chart, और क्यों?

  1. Line chart: semesters ordered हैं, और slope उनके पार trend दिखाता है
  2. Scatter plot: कोई भी दो numeric columns का मतलब है scatter
  3. Bar chart: totals हमेशा bars होते हैं
  4. Histogram: marks हमेशा histogram में जाते हैं
Show the answer

Line chart: semesters ordered हैं, और slope उनके पार trend दिखाता है

Semesters 1 से 4 एक natural sequence बनाते हैं, और सवाल उस sequence के साथ बदलाव के बारे में है: line chart का exact territory: slope literally जवाब देता है "improve हो रहा है या decline?"। Scatter order छोड़ देता है (और 4 points के साथ, लगभग कुछ नहीं दिखाता), bars काम कर जाते पर सवाल जो trend माँगता है उसे दबा देते, और एक histogram बिल्कुल अलग सवाल का जवाब देता है (distribution, अगला lesson)।

Think first

Slope जिसने झूठ बोला

एक chart DBMS को 62 → 58 → 51 गिरता दिखाता है... पर y axis 50 से 63 तक चलता है, जिससे line एक cliff की तरह गिरती दिखती है। tap करने से पहले: क्या DATA ग़लत है, और panic करने से पहले एक careful reader को क्या check करना चाहिए?

Show the answer

Data honest है; axis dramatic है। 50..63 तक clip किया गया y axis एक 11-point dip को पूरी chart height में फैला देता है, visual panic को तीन गुना करते हुए।

Careful readers हमेशा पहले y-axis range check करते हैं। Chart-maker के रूप में, या तो zero के पास शुरू कीजिए या range को साफ़ label कीजिए: exams (और newspapers) truncated-axis exaggerations से भरे हैं, और "axis scale check कीजिए" वह professional reflex है जो यह lesson install करना चाहता है।

Watch out

तीन line-chart slips

Unordered categories के through lines: x पर cities या student names के साथ एक connecting line एक ऐसे सफ़र का दावा करती है जो मौजूद नहीं: वह bar-chart territory है (दो lessons आगे)।

label= भूल जाना: legend() एक empty box दिखाता है; हर series को plot() के समय उसका नाम चाहिए।

Axis drama: truncated y axes slopes को exaggerate करते हैं: scale को ध्यान में रखते हुए पढ़िए और design कीजिए।

Theory

Dashboard chart

Line charts दुनिया के dashboards चलाते हैं: महीनों में sensex, daily active users, घंटे के हिसाब से temperature, हफ़्ते के हिसाब से आपका अपना weight। कोई भी metric-over-time सवाल default से line पर जाता है। Staff meeting में दिखाई गई ResultDesk की गिरती DBMS line वह पल है जब इस subject का tooling institutional evidence बन जाता है: अगला, distributions (histogram) और category comparisons (bar) kit पूरा करते हैं।

Summary

Key takeaways

  • plt.plot(x, y) ordered points जोड़ता है: slope ही story है (rising, falling, kinks)।
  • सिर्फ़ एक naturally ORDERED x के साथ lines plot कीजिए: tests, months, years।
  • कई series: प्रति line एक plot(label=...), फिर legend()।
  • marker='o' असली data points दिखाता है; styling के लिए linestyle/color।
  • किसी dramatic slope पर भरोसा करने से पहले y-axis range check कीजिए: truncation exaggerate करता है।
  • Line = order के पार trend; scatter = records के पार relation; bar = categories।
  • Memory hook: dots जोड़िए, slope पढ़िए।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Data Visualization using dataframe

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati