Learn how to structure and understand data for line charts in Python, including x-axis and y-axis values, monthly trends, and beginner-friendly plotting examples.
Before creating a chart, we need to understand the data.
We will use a university student enrollment dataset.
| Month | Students Enrolled |
|---|---|
| January | 50 |
| February | 65 |
| March | 60 |
| April | 80 |
| May | 75 |
| June | 100 |
| July | 110 |
| August | 95 |
| September | 120 |
| October | 130 |
| November | 125 |
| December | 150 |
Consider the following example:
| Month | Students Enrolled |
|---|---|
| January | 50 |
| February | 65 |
A line chart normally has two axes.
Horizontal axis
Month
January, February, March, and so on.
Vertical axis
Number of Students
50, 65, 60, 80, and so on.
Each month has a corresponding enrollment value.
For example:
| Month | Students | Chart point |
|---|---|---|
| January | 50 | January → 50 |
| February | 65 | February → 65 |
| March | 60 | March → 60 |
| April | 80 | April → 80 |
The chart places each point according to its month and numerical value.
Then, the points are connected with lines.
Important: The X-axis shows the order or position of the data, while the Y-axis shows the corresponding numerical values.
Use a line chart when:
Line charts work best when the X-axis follows a meaningful sequence.
For example:
January → February → March → April
This order makes sense because months follow a natural sequence.
However, consider these unrelated categories:
Computer Science → English → Physics → Biology
Connecting these subjects with a line may suggest a continuous progression that does not actually exist.
A bar chart would usually be more appropriate for comparing unrelated subjects.
Avoid line charts when:
| Feature | Line Chart | Bar Chart | Area Chart | Scatter Plot |
|---|---|---|---|---|
| Purpose | Show trends | Compare values | Show trends and magnitude | Show relationships |
| Suitable data | Ordered data | Categories | Ordered data | Paired numerical values |
| Best use case | Monthly sales | Sales by product | Population growth over time | Height vs weight |
| Main difference | Connects points | Uses rectangular bars | Fills area below line | Uses unconnected points |
Practical examples:
A line chart contains several important components.
| Component | Explanation |
|---|---|
| Chart Title | Describes what the chart represents. |
| X-axis | Horizontal axis, usually representing time or ordered categories. |
| Y-axis | Vertical axis, representing numerical values. |
| X-axis Values | Values displayed along the horizontal axis. |
| Y-axis Values | Numerical scale displayed along the vertical axis. |
| Data Points | Individual points representing observations. |
| Connecting Lines | Lines joining data points. |
| Axis Labels | Names describing each axis. |
| Tick Marks | Small marks showing positions on an axis. |
| Gridlines | Reference lines that help read values. |
| Legend | Identifies different lines when multiple datasets are displayed. |
|  |
Increasing Trend
Values move upward.
Decreasing Trend
Values move downward.
Constant Trend
Values remain unchanged.
Fluctuating Trend
Values repeatedly rise and fall.
A multiple line chart displays two or more datasets on the same chart.
For example, we can compare monthly enrollment in:
Each department gets a separate line and a legend identifies each line.
|  |
Remember: Use different colors or markers to make multiple lines easy to distinguish.