import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Replace the following with your own dataframe
# Events=pd.read_csv('StartFinish.csv')
Events = np.random.randint(0, 10, size=(24, 2))
Events = pd.DataFrame(Events, columns=['xCoordinate', 'yCoordinate'])
Events['Event Type'] = 'Start'
Events.loc[1::2, 'Event Type'] = 'Finish'
Scatter = sns.scatterplot(x='xCoordinate', y='yCoordinate', hue='Event Type', data=Events)
Scatter
for n in range(0, len(Events), 2):
plt.plot([Events.loc[n, 'xCoordinate'], Events.loc[n+1, 'xCoordinate']], [Events.loc[n, 'yCoordinate'], Events.loc[n+1, 'yCoordinate']], 'k--')
结果将是
如果您想要更像熊猫的东西,请尝试以下方法:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Replace the following with your own dataframe
# Events=pd.read_csv('StartFinish.csv')
np.random.seed(0)
Events = np.random.randint(0, 10, size=(24, 2))
Events = pd.DataFrame(Events, columns=['xCoordinate', 'yCoordinate'])
Events['Event Type'] = 'Start'
Events.loc[1::2, 'Event Type'] = 'Finish'
Scatter = sns.scatterplot(x='xCoordinate', y='yCoordinate', hue='Event Type', data=Events)
Scatter
Events['group'] = Events.index//2
Events.groupby('group').apply(lambda x: plt.plot([x.loc[0, 'xCoordinate'], x.loc[1, 'xCoordinate']],
[x.loc[0, 'yCoordinate'], x.loc[1, 'yCoordinate']], 'k--'));