Scatter plot is a graph in which the values of two variables are plotted along two axes. It is a most basic type of plot that helps you visualize the relationship between two variables.
Concept
- What is a Scatter plot?
- Basic Scatter plot in python
- Correlation with Scatter plot
- Changing the color of groups of points
- Changing the Color and Marker
- Scatter plot with Linear fit plot using seaborn
- Scatter Plot with Histograms using seaborn
- Bubble plot
- Exploratory Analysis using mtcars Dataset
- Multiple line of best fits
- Adjusting color and style for different categories
- Text Annotation in Scatter Plot
- Bubble Plot with categorical variables
- Categorical Plot
What is a Scatter plot?
Scatter plot is a graph of two sets of data along the two axes. It is used to visualize the relationship between the two variables.
If the value along the Y axis seem to increase as X axis increases[or decreases], it could indicate a positive [or negative] linear relationship. Whereas, if the points are randomly distributed with no obvious pattern, it could possibly indicate a lack of dependent relationship.
In python matplotlib, the scatterplot can be created using the
# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
9 or the # Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
0. Using these functions, you can add more feature to your scatter plot, like changing the size, color or shape of the points.So what is the difference between
# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
1 vs # Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
2?The difference between the two functions is: with
9 any property you apply [color, shape, size of points] will be applied across all points whereas in # Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
0 you have more control in each point’s
appearance.# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
That is, in
# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
1 you can have the color, shape and size of each dot [datapoint] to vary based on another variable. Or even the same variable [y]. Whereas, with # Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
9, the properties you set will be applied to all the points in the chart.First, I am going to import the libraries I will be using.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
The
# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
7 function is used to change the default parameters of the plot’s figure.Basic Scatter plot in python
First, let’s create artifical data using the
# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
8. You need to specify the no. of points you require as the arguments.You can also specify the lower and upper limit of the random variable you need.
Then use the
# Simple Scatterplot with colored points
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y, c=y, cmap='Spectral']
plt.colorbar[]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
1 function to draw a scatter plot using matplotlib. You need to specify the variables x and y as arguments.# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
0 is used to set title to your
plot.# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
1 is used to label the x axis.# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
2 is used to label the y axis.Get Free Complete Python Course
Facing the same situation like everyone else?
Build your data science career with a globally recognised, industry-approved qualification. Get the mindset, the confidence and the skills that make Data Scientist so valuable.
# Linear - Line of best fit import
seaborn as sns url = '//gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv' df=pd.read_csv[url] plt.rcParams.update[{'figure.figsize':[10,8],
'figure.dpi':100}] sns.lmplot[x='mpg', y='disp', data=df] plt.title["Scatter Plot with
Linear fit"];
You can see that we are getting a negative corelation between the 2 columns.
if[typeof ez_ad_units != 'undefined']{ez_ad_units.push[[[336,280],'machinelearningplus_com-large-leaderboard-2','ezslot_1',550,'0','0']]};__ez_fad_position['div-gpt-ad-machinelearningplus_com-large-leaderboard-2-0'];# Scatter Plot with lowess line fit url = '//gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv' df=pd.read_csv[url] sns.lmplot[x='mpg', y='disp', data=df, lowess=True] plt.title["Scatter Plot with Lowess fit"];
Scatter Plot with Histograms using seaborn
Use the joint plot function in seaborn to represent the scatter plot along with the distribution of both x and y values as historgrams.
if[typeof ez_ad_units != 'undefined']{ez_ad_units.push[[[336,280],'machinelearningplus_com-leader-1','ezslot_6',560,'0','0']]};__ez_fad_position['div-gpt-ad-machinelearningplus_com-leader-1-0'];Sử dụng hàm
# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
7 với X, Y và DATSET làm đối số.import seaborn as sns
x = np.random.randn[100]
y1 = np.random.randn[100]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
sns.jointplot[x=x,y=y1];
Như bạn có thể thấy, chúng tôi cũng đang nhận được biểu đồ phân phối cho giá trị x và y.
Âm mưu bong bóng
Một biểu đồ bong bóng là một biểu đồ phân tán trong đó một chiều thứ ba được thêm vào: giá trị của một biến bổ sung được biểu thị thông qua kích thước của các dấu chấm.
Bạn cần thêm một lệnh khác trong biểu đồ phân tán
# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
8 đại diện cho kích thước của các điểm.# Bubble Plot. The size of points changes based on a third varible.
x = np.random.rand[100]
y = np.random.rand[100]
s = np.random.rand[100]*200
plt.scatter[x, y, s=s,color='red']
plt.show[]
Kích thước của bong bóng biểu thị giá trị của đồng xu thứ ba, nếu kích thước bong bóng nhiều hơn thì điều đó có nghĩa là giá trị của Z là lớn tại thời điểm đó.
Phân tích khám phá của bộ dữ liệu MTCARS
Bộ dữ liệu MTCARS chứa các thông số kỹ thuật của số dặm và xe của nhiều mẫu xe. Bộ dữ liệu có thể được tải xuống ở đây.
Mục tiêu của phân tích thăm dò là để hiểu mối quan hệ giữa các thông số kỹ thuật và số dặm khác nhau.
df=pd.read_csv["mtcars.csv"]
df.head[]
Bạn có thể thấy rằng bộ dữ liệu chứa các thông tin khác nhau về một chiếc xe hơi.
Trước tiên, hãy để Lôi thấy một biểu đồ phân tán để thấy sự phân phối giữa
# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
9 và # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
0 và phân phối biểu đồ của chúng. Bạn có thể làm điều này bằng cách sử dụng chức năng # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
1 ở Seaborn.# joint plot for finding distribution
sns.jointplot[x=df["mpg"], y=df["disp"],color='red', kind='scatter']
# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
0Nhiều dòng phù hợp tốt nhất
Nếu bạn cần thực hiện regrssion tuyến tính phù hợp với nhiều loại tính năng giữa X và Y, như trong trường hợp này, tôi sẽ chia thêm các danh mục được tích lũy thành
# Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
2 và cố gắng phù hợp với một đường tuyến tính cho phù hợp. Đối với điều này, hãy sử dụng đối số # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
3 trong hàm # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
4.# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
1Xem rằng chức năng đã phù hợp với 3 dòng khác nhau cho 3 loại bánh răng trong bộ dữ liệu.
Điều chỉnh màu sắc và phong cách cho các loại khác nhau
Tôi đã chia bộ dữ liệu theo các loại thiết bị khác nhau. Sau đó, tôi vẽ chúng một cách riêng biệt bằng cách sử dụng hàm
# Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
5.# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
2# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
3Chú thích văn bản trong biểu đồ phân tán
Nếu bạn cần thêm bất kỳ văn bản nào trong biểu đồ của bạn, hãy sử dụng hàm
# Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
6 với văn bản và tọa độ nơi bạn cần thêm văn bản làm đối số.# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
4# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
5Biểu đồ bong bóng với các biến phân loại
Thông thường bạn sẽ sử dụng 2 varibales để vẽ biểu đồ phân tán [x và y], sau đó tôi đã thêm một biến phân loại khác
# Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
7 sẽ được ngụ ý bởi màu của các điểm, tôi cũng đã thêm một biến khác # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
8 có giá trị sẽ được ngụ ý theo cường độ của mỗi màu.# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
6# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
7Tôi đã vẽ giá trị
# Scatterplot of non-random vzriables
x=np.arange[1,10,0.2]
y= np.exp[x]
plt.scatter[x,y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Exponential Relation dataset']
plt.show[]
9 so với giá trị # Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
0 và cũng chia chúng thành các màu khác nhau đối với # Scatterplot - Color Change
x = np.random.randn[50]
y1 = np.random.randn[50]
y2= np.random.randn[50]
# Plot
plt.scatter[x,y1,color='blue']
plt.scatter[x,y2,color= 'red']
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
# Decorate
plt.title['Color Change']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
1Value và kích thước của mỗi bong bóng đại diện cho giá trị # Scatterplot - Color Change
x = np.random.randn[50]
y1 = np.random.randn[50]
y2= np.random.randn[50]
# Plot
plt.scatter[x,y1,color='blue']
plt.scatter[x,y2,color= 'red']
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
# Decorate
plt.title['Color Change']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
2.# Scatterplot - Color Change
x = np.random.randn[50]
y1 = np.random.randn[50]
y2= np.random.randn[50]
# Plot
plt.scatter[x,y1,color='blue']
plt.scatter[x,y2,color= 'red']
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
# Decorate
plt.title['Color Change']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
3 Tham số được sử dụng để điều chỉnh cường độ màu của lô. Nhiều aplha hơn sẽ là cường độ màu.Cốt truyện phân loại
# Simple Scatterplot
x = range[50]
y = range[50] + np.random.randint[0,30,50]
plt.scatter[x, y]
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.title['Simple Scatter plot']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
8# Scatterplot - Color Change
x = np.random.randn[50]
y1 = np.random.randn[50]
y2= np.random.randn[50]
# Plot
plt.scatter[x,y1,color='blue']
plt.scatter[x,y2,color= 'red']
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
# Decorate
plt.title['Color Change']
plt.xlabel['X - value']
plt.ylabel['Y - value']
plt.show[]
4 được sử dụng để cung cấp quyền truy cập vào một số hàm cấp trục cho thấy mối quan hệ giữa một biến số và một hoặc nhiều biến phân loại sử dụng một trong một số biểu diễn trực quan.Sử dụng lệnh
# Scatterplot and Correlations
# Data
x=np.random.randn[100]
y1= x*5 +9
y2= -5*x
y3=np.random.randn[100]
# Plot
plt.rcParams.update[{'figure.figsize':[10,8], 'figure.dpi':100}]
plt.scatter[x, y1, label=f'y1 Correlation = {np.round[np.corrcoef[x,y1][0,1], 2]}']
plt.scatter[x, y2, label=f'y2 Correlation = {np.round[np.corrcoef[x,y2][0,1], 2]}']
plt.scatter[x, y3, label=f'y3 Correlation = {np.round[np.corrcoef[x,y3][0,1], 2]}']
# Plot
plt.title['Scatterplot and Correlations']
plt.legend[]
plt.show[]
3 để chia thêm dữ liệu thành các loại khác.Bài viết đề xuất
- Top 50 trực quan hóa matplotlib
- Hướng dẫn Matplotlib
- Matplotlib pyplot
- Biểu đồ matplotlib
- Biểu đồ thanh trong Python
- Biểu đồ hộp trong Python