我怎样才能得到这样的情节?不知道它是什么情节
How can I get such a plot? Do not know the type of plot it is
我有这样的数据:
file | timestamps
1 | 02/01/1970
1 | 03/01/1970
1 | 04/01/1970
1 | 05/01/1970
2 | 06/01/1970
2 | 07/01/1970
3 | 08/01/1970
3 | 09/01/1970
3 | 10/01/1970
在 x 轴上,我想要每个 file
的行数。在 y 轴上,我想要 timestamps
。它看起来应该类似于这个情节,但我不知道如何得到这个情节。这是瀑布图吗?
数据不多,但这是您示例的结果
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import pandas as pd
data = [[1, '02/01/1970'],
[1, '03/01/1970'],
[1, '04/01/1970'],
[1, '05/01/1970'],
[2, '06/01/1970'],
[2, '07/01/1970'],
[3, '08/01/1970'],
[3, '09/01/1970'],
[3, '10/01/1970']]
df = pd.DataFrame(data, columns = ['file', 'timestamps'])
df['timestamps'] = pd.to_datetime(df['timestamps'], format = '%d/%m/%Y')
tot_delta_d = 0
tot_file = 0
fig, ax = plt.subplots()
for f in df['file'].unique():
delta_d = df[df['file'] == f]['timestamps'].max() - df[df['file'] == f]['timestamps'].min()
rect = patches.Rectangle((tot_delta_d, tot_file),
delta_d.days,
df[df['file'] == f].shape[0],
color='indigo')
ax.add_patch(rect)
tot_delta_d += delta_d.days
tot_file += df[df['file'] == f].shape[0]
plt.xlim([0, tot_delta_d])
plt.ylim([0, tot_file])
ax.set_xlabel('Parquets')
ax.set_ylabel('Timestamps')
ax.invert_yaxis()
plt.show()
输出:
我有这样的数据:
file | timestamps
1 | 02/01/1970
1 | 03/01/1970
1 | 04/01/1970
1 | 05/01/1970
2 | 06/01/1970
2 | 07/01/1970
3 | 08/01/1970
3 | 09/01/1970
3 | 10/01/1970
在 x 轴上,我想要每个 file
的行数。在 y 轴上,我想要 timestamps
。它看起来应该类似于这个情节,但我不知道如何得到这个情节。这是瀑布图吗?
数据不多,但这是您示例的结果
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import pandas as pd
data = [[1, '02/01/1970'],
[1, '03/01/1970'],
[1, '04/01/1970'],
[1, '05/01/1970'],
[2, '06/01/1970'],
[2, '07/01/1970'],
[3, '08/01/1970'],
[3, '09/01/1970'],
[3, '10/01/1970']]
df = pd.DataFrame(data, columns = ['file', 'timestamps'])
df['timestamps'] = pd.to_datetime(df['timestamps'], format = '%d/%m/%Y')
tot_delta_d = 0
tot_file = 0
fig, ax = plt.subplots()
for f in df['file'].unique():
delta_d = df[df['file'] == f]['timestamps'].max() - df[df['file'] == f]['timestamps'].min()
rect = patches.Rectangle((tot_delta_d, tot_file),
delta_d.days,
df[df['file'] == f].shape[0],
color='indigo')
ax.add_patch(rect)
tot_delta_d += delta_d.days
tot_file += df[df['file'] == f].shape[0]
plt.xlim([0, tot_delta_d])
plt.ylim([0, tot_file])
ax.set_xlabel('Parquets')
ax.set_ylabel('Timestamps')
ax.invert_yaxis()
plt.show()
输出: