使用 Python 绘制学生进度图

Using Python to graph student progress

我是第一次尝试 python 绘图,我想通过绘制学生的一些进度图来尝试我学到的东西。我的进度数据采用 table 格式,与我在下面模拟的格式相同。我已经使用 MSPaint(抱歉)模拟了我认为会是一个不错的图表来向他们展示他们的进步。

这种图表的正确名称是什么?实现它的第一步是什么?我在 http://matplotlib.org/ or on https://plot.ly/

上看不到任何类似的内容

请随时告诉我我的图表布局有误。

这可能就是您要找的东西

import matplotlib.pyplot as plt

weeks = range(1,6)
steve = [1, 3, 4, 4, 5]
bob = [2, 3, 4, 4, 5]
ralph = [3, 3, 4, 5, 5]

plt.figure()
plt.plot(weeks, bob, label='Bob')
plt.plot(weeks, steve, label='Steve')
plt.plot(weeks, ralph, label='Ralph')
plt.title('Student Progress')
plt.ylabel('Score')
plt.xlabel('Week')
plt.xticks(range(6))
plt.ylim(0, 6)
plt.legend(loc='lower right')
plt.show()

我尝试在 matplotlib 中生成您的示例图表。我怀疑其他具有更强 matplotlib-foo 的人可以大大改善这一点:)

import matplotlib.pyplot as plt
import numpy as np

students = ['steve', 'bob', 'ralph']
progress = [
[1, 3, 4, 4, 5],
[2, 3, 4, 4, 5],
[3, 3, 4, 5, 5]]

(fig, ax) = plt.subplots(1, 1)

# Offset lines by some fraction of one
dx = 1.0 / len(progress)
xoff = dx / 2.0
for i, (name, data) in enumerate(zip(students, progress)):
  ax.plot(np.arange(len(data)) + xoff, data, label=name, marker='o')
  xoff += dx

ax.set_xticks(np.arange(0, len(progress[0]) + 0.01, dx), minor=True)
ax.set_xticks(np.arange(1, len(progress[0])+1))
labels = students * len(progress[0])
week = 1
for i,l in enumerate(labels):
  if l == students[1]:
    # hack to add Week label below the second label for each block
    labels[i] = "%s\nWeek %s" % (l, week)
    week += 1
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

ax.set_xticklabels(labels, fontsize=8, ha='left', minor=True)
ax.set_xticklabels([])
ax.tick_params(which='both', direction = 'out')
ax.tick_params(axis='x', which='major', width=4)
ax.tick_params(axis='x', which='major', length=7)
ax.tick_params(axis='y', which='major', width=0, length=0)

ax.set_ylim(0, 6)
ax.set_yticks(range(1, 6))

ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

ax.set_title("Student Progress")

ax.legend(loc='best')

fig.show()

尝试bokeh. It supports categorical axes, and additionally supports datetime categorical axes (docs link)