我有一个由 truthIds 和 trackIds 组成的数据框:
truthId = ['A', 'A', 'B', 'B', 'C', 'C', 'A', 'C', 'B', 'A', 'A', 'C', 'C']
trackId = [1, 1, 2, 2, 3, 4, 5, 3, 2, 1, 5, 4, 6]
df1 = pd.DataFrame({'truthId': truthId, 'trackId': trackId})
trackId truthId
0 1 A
1 1 A
2 2 B
3 2 B
4 3 C
5 4 C
6 5 A
7 3 C
8 2 B
9 1 A
10 5 A
11 4 C
12 …Run Code Online (Sandbox Code Playgroud) 我有一个简单的 pandas 数据框,我想用 matplotlib 绘制它:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel('SAT_data.xlsx', index_col = 'State')
plt.figure()
plt.scatter(df['Year'], df['Reading'], c = 'blue', s = 25)
plt.scatter(df['Year'], df['Math'], c = 'orange', s = 25)
plt.scatter(df['Year'], df['Writing'], c = 'red', s = 25)
Run Code Online (Sandbox Code Playgroud)
这是我的情节:

我想将蓝色数据点向左移动一点,将红色数据点向右移动一点,因此每年 x 轴上都有三个迷你散点数据列,而不是所有三个数据集都重叠。我尝试并未能正确使用“verts”参数。有一个更好的方法吗?