2015-08-30 86 views
1

我正在试验第一次使用python绘图,我想通过绘制学生的一些进度来学习我所学到的东西。我的进度数据与下面我嘲笑的格式相同。我用MSPaint(抱歉)嘲笑我认为是一张体面的图表,向他们展示他们的进步。使用Python绘制学生进度图

什么是这种类型的图的正确名称,什么是实现它的第一步?我看不到任何相似的东西http://matplotlib.org/https://plot.ly/

请随时告诉我,我正在铺设图全错了。 Quick MSpaint mockup

+0

也许这可以让你在正确的轨道上:http://matplotlib.org/examples/api/barchart_demo.html G1,G2 ...可能是你的周,和男人/女人是你的学生。 –

回答

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() 

example figure

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() 

enter image description here

+0

当两个学生每周都有相同的情况时,给每条线条添加不同的短划线风格会更加明显(在这个例子中,鲍勃很难挑选出来 - 第4周到5周,他是怎么做的?) – cphlewis

0

尝试bokeh。它支持分类轴,并且还支持日期时间分类轴(docs link