Skip to content

Commit 751cadf

Browse files
Merge branch 'main' into term/cpp-unordered-set-cbegin-8031
2 parents ba01673 + 1e9e9cb commit 751cadf

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/kotlin/concepts/variables/variables.md
1+
content/kotlin/concepts/classes/classes.md
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
Title: '.plot()'
3+
Description: 'Creates line and marker plots to visualize relationships between variables in Matplotlib.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Data Visualization'
7+
Tags:
8+
- 'Charts'
9+
- 'Matplotlib'
10+
- 'Methods'
11+
- 'Python'
12+
CatalogContent:
13+
- 'learn-python-3'
14+
- 'paths/data-science'
15+
- 'paths/data-science-foundations'
16+
---
17+
18+
The **`.plot()`** function in [Matplotlib](https://www.codecademy.com/resources/docs/matplotlib/pyplot) is the primary method used to create line plots and marker plots. It takes one or two sets of data points (x and y coordinates) and draws lines connecting them, displays markers at each point, or both. This function is one of the most commonly used tools in data visualization for showing trends, patterns, and relationships between variables.
19+
20+
Line plots are ideal for illustrating how data changes over time or across continuous intervals. It's widely used in fields such as statistics, engineering, and data science for exploratory data analysis and model visualization.
21+
22+
## Syntax
23+
24+
```pseudo
25+
matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)
26+
```
27+
28+
**Parameters:**
29+
30+
- `*args`: Values for y, or x and y, optionally followed by a format string.
31+
- `scalex`: Auto-scale the x-axis (default True).
32+
- `scaley`: Auto-scale the y-axis (default True).
33+
- `data`: Optional dict or DataFrame for referencing variables by name.
34+
- `**kwargs`: Style and configuration options like color, label, linewidth, marker.
35+
36+
**Return value:**
37+
38+
Returns a list of `Line2D` objects representing the plotted data.
39+
40+
## Example: Creating a Basic Line Plot
41+
42+
This example demonstrates how to create a simple line plot with plt.plot() to visualize the relationship between two numerical variables:
43+
44+
```py
45+
import matplotlib.pyplot as plt
46+
import numpy as np
47+
48+
# Sample data
49+
x = np.array([1, 2, 3, 4, 5])
50+
y = np.array([2, 4, 1, 6, 3])
51+
52+
# Create a line plot
53+
plt.plot(x, y)
54+
55+
# Add labels and a title
56+
plt.xlabel('X-axis')
57+
plt.ylabel('Y-axis')
58+
plt.title('Basic Line Plot Example')
59+
60+
# Add a grid for better readability
61+
plt.grid(True, linestyle='--', alpha=0.6)
62+
63+
# Display the plot
64+
plt.show()
65+
```
66+
67+
This example visualizes the relationship between an independent variable, X-axis, and a dependent variable, Y-axis, using a single continuous line. The plot shows the change in Y values as X increases from 1.0 to 5.0. This plot highlights a few useful details worth noting:
68+
69+
- Single Series: The plot displays one series of data, represented by a single blue line, showing the progression of the Y-axis value relative to the X-axis value.
70+
- Data Points and Trend: The line connects the following data points: $(1.0, 2.0)$, $(2.0, 4.0)$, $(3.0, 1.0)$, $(4.0, 6.0)$, and $(5.0, 3.0)$. The plot illustrates clear changes in direction: an initial increase, a sharp decrease, a significant increase to the maximum value, and a final decrease.
71+
- Labels and Title: The plot is clearly titled "Basic Line Plot Example" and has "X-axis" and "Y-axis" labels for clarity.
72+
- Grid: A light dashed grid is present, running horizontally and vertically across the plot, which aids in precisely reading the coordinate values of the data points off the chart.
73+
74+
![Line plot illustrating a fluctuating, piecewise linear trend between the X-axis and Y-axis, with a single blue line connecting 5 data points, a grid, and labeled axes](https://raw.githubusercontent.com/Codecademy/docs/main/media/matplot-plot-output.png)

content/sql/concepts/joins/joins.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,40 @@ An `OUTER JOIN` will combine rows from different tables even if the join conditi
4040
- [`RIGHT JOIN`](https://www.codecademy.com/resources/docs/sql/commands/right-join), which combines matches with all rows from the right-side table.
4141
- [`FULL OUTER JOIN`](https://www.codecademy.com/resources/docs/sql/commands/full-outer-join), which combines matches with all rows from the left- and right-side tables.
4242

43+
## CROSS JOIN
44+
45+
A `CROSS JOIN` clause combines each row from one table with each row from another in the result set. This result is also known as a `Cartesian product`. The following query returns every combination of `shirt_color` and `pants_color`:
46+
47+
```sql
48+
SELECT shirts.shirt_color,
49+
pants.pants_color
50+
FROM shirts
51+
CROSS JOIN pants;
52+
```
53+
54+
For example, here's the `shirts` table:
55+
56+
| shirt_color |
57+
| ----------- |
58+
| white |
59+
| grey |
60+
61+
And the `pants` table:
62+
63+
| pants_color |
64+
| ----------- |
65+
| light |
66+
| dark |
67+
68+
The result of the query would contain every combination of the two tables:
69+
70+
| shirt_color | pants_color |
71+
| ----------- | ----------- |
72+
| white | light |
73+
| white | dark |
74+
| grey | light |
75+
| grey | dark |
76+
4377
## UNION
4478

4579
The [`UNION`](https://www.codecademy.com/resources/docs/sql/commands/union) clause is used to combine results that appear from multiple [`SELECT`](https://www.codecademy.com/resources/docs/sql/commands/select) statements and filter duplicates.

media/matplot-plot-output.png

34.2 KB
Loading

0 commit comments

Comments
 (0)