我第一次尝试使用python图形,我想通过绘制学生的一些进展来尝试我学到的东西。我的进度数据在一个表格中,其格式与我在下面模拟的格式相同。我曾经使用MSPaint(对不起)来模拟我认为是一个体面的图表来向他们展示他们的进展。
此类图表的正确名称是什么,实现它的第一步是什么?我在http://matplotlib.org/或https://plot.ly/
上看不到任何相似内容答案 0 :(得分:1)
我在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()
答案 1 :(得分:0)
这样的事情可能就是你要找的东西
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()
答案 2 :(得分:0)