Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- pie charts
- MySQL
- polynomial regression
- __init__
- AS
- line width
- continue
- matplotlib.pyplot
- self parameter
- start exercise
- line color
- Else
- Default X points
- PROJECT
- PANDAS
- error
- Github
- Text mining
- matplotlib
- train/test
- SQL
- Text Analytics
- variables
- machine learning
- multiple lines
- break
- Python
- iterates
- For loops
- data distribution
Archives
- Today
- Total
Data Science Explorer
Matplotlib Scatter 본문
반응형
- Creating Scatter Plots
You can use the scatter() function to draw a scatter plot.
Example
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 4, 6, 2])
y = np.array([4, 5, 2, 1])
plt.scatter(x, y)
plt.show()
Result
- Compare plots
Example
import matplotlib.pyplot as plt
import numpy as np
#day one, the age and speed of 13 cars:
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
#day two, the age and speed of 15 cars:
x = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
y = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
plt.scatter(x, y)
plt.show()
Result
- Adjusting the color
You can use the c argument to adjust the color.
import matplotlib.pyplot as plt
import numpy as np
x = np.array([2,8,9,1])
y = np.array([5,5,5,5])
colors = np.array(["red","green","blue","magenta"])
plt.scatter(x, y, c=colors)
plt.show()
Result
- Size
Use s argument to adjust the size of the dots.
Example
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 20, 30, 40, 50]
# Define the size of dots
dot_size = [100, 200, 300, 400, 500]
# Create the scatter plot
plt.scatter(x, y, s=dot_size, label='Dots', c='blue')
# Add labels and a legend
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
# Show the plot
plt.show()
Result
- Alpha
You can adjust the transparency of the dots with the alpha argument
Example
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 20, 30, 40, 50]
# Define the size of dots
dot_size = [100, 200, 300, 400, 500]
# Create the scatter plot
plt.scatter(x, y, s=dot_size, label='Dots', c='blue', alpha =0.3)
# Add labels and a legend
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
# Show the plot
plt.show()
Result
'Python' 카테고리의 다른 글
Matplotlib Histograms (0) | 2023.11.10 |
---|---|
Matplotlib Bars (2) | 2023.11.09 |
Matplotlib Subplot (0) | 2023.11.07 |
Matplotlib: Matplotlib Adding Grid Lines (0) | 2023.11.06 |
Matplotlib: Matplotlib Line (0) | 2023.11.05 |