2015-09-18 55 views
2

我在pyplot上有兩個boxlot,我想把'1'和'2'的yticks改爲兩個'Post Index'和'Pre Index'。這將如何完成?如何更改pyplot上的yticks?

import numpy as np 
import matplotlib.pyplot as plt 

pre_data = [1,1,3,2,2,2,3,1,1,1] 
post_data = [1,1,2,3,1] 
data = [pre_data, post_data] 

pre_mean = np.mean(pre_data) 
post_mean = np.mean(post_data) 

plt.boxplot(data,0,'',0) 
plt.xlabel('Duration in Seconds') 
plt.title('Example Plot') 

plt.show() 

回答

1

你只需要設置當前軸的yticklabelsgca()獲得當前軸)

plt.gca().set_yticklabels(['Post Index', 'Pre Index']) 

enter image description here

+0

工作正是我visioned,謝謝@湯姆 – kekethetabbycat