matplotlib 散点图
示例
一个简单的散点图
importmatplotlib.pyplotas plt
# Data
x = [43,76,34,63,56,82,87,55,64,87,95,23,14,65,67,25,23,85]
y = [34,45,34,23,43,76,26,18,24,74,23,56,23,23,34,56,32,23]
fig, ax = plt.subplots(1, figsize=(10, 6))
fig.suptitle('Example Of Scatterplot')
# Create the Scatter Plot
ax.scatter(x, y,
color="blue", # Color of the dots
s=100, # Size of the dots
alpha=0.5, # Alpha/transparency of the dots (1 is opaque, 0 is transparent)
linewidths=1) # Size of edge around the dots
# Show the plot
plt.show()带有标记点的散点图
importmatplotlib.pyplotas plt
# Data
x = [21, 34, 44, 23]
y = [435, 334, 656, 1999]
labels = ["alice", "bob", "charlie", "diane"]
# Create the figure and axes objects
fig, ax = plt.subplots(1, figsize=(10, 6))
fig.suptitle('Example Of Labelled Scatterpoints')
# Plot the scatter points
ax.scatter(x, y,
color="blue", # Color of the dots
s=100, # Size of the dots
alpha=0.5, # Alpha of the dots
linewidths=1) # Size of edge around the dots
# Add the participant names as text labels for each point
for x_pos, y_pos, label in zip(x, y, labels):
ax.annotate(label, # The label for this point
xy=(x_pos, y_pos), # Position of the corresponding point
xytext=(7, 0), # Offset text by 7 points to the right
textcoords='offset points', # tell it to use offset points
ha='left', # Horizontally aligned to the left
va='center') # Vertical alignment is centered
# Show the plot
plt.show()
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下