2017-04-22 208 views
0

我想繪製使用不同線條樣式的多個直方圖,因爲我無法使用顏色區分它們。我明白了,但這些看起來非常相似,因爲兩個地塊的分佈非常相似。我可以得到不同的標記,如點,星星等,或者更好的方法來區分這些? 這是我使用不同線條樣式繪製多個直方圖python

import matplotlib 
matplotlib.use('PS') 
import matplotlib.pyplot as plt 
plt.hist(values1, histtype='step', linestyle=':',label=topic1) 
plt.hist(values2, histtype='step', linestyle='--',color=color, label=topic2) 
plt.hist(values3,histtype='step', linestyle='solid', label=topic3) 

plt.legend(loc="upper right") 
plt.legend(frameon=False) 
plt.show() 
plt.savefig(allplotfile) 
plt.close() 

enter image description here

回答

2

您可以使用孵化,例如hatch="\\\\"致電hist。我不相信它看起來更好,但它至少是一種選擇。

enter image description here

import matplotlib.pyplot as plt 
plt.style.use("grayscale") 
import numpy as np; np.random.seed(1) 
plt.rcParams["figure.figsize"] = (4,3) 

vals = np.arange(2,5.1,0.5) 
p = np.array([1,.2,.36,.15,.38,.28,.4]) 
p = p/np.sum(p) 
a = np.random.choice(vals, size=100, p=p) 
b = np.random.choice(vals, size=100, p=p) 
c = np.random.choice(vals, size=100, p=p) 


plt.hist(a, histtype='step', linestyle=':',label="topic1", hatch="\\\\") 
plt.hist(b, histtype='step', linestyle='--', label="topic2", hatch="//") 
plt.hist(c,histtype='step', linestyle='solid', label="topic3", hatch="++") 

plt.legend(loc="upper right") 
plt.legend(frameon=False) 
plt.show() 

不同線寬還可以幫助:lw=2等,
(這裏我用123如線寬)

enter image description here

不同SH灰色的ADE,結合阿爾法設置,還可以幫助:

plt.hist(a, linestyle=':', color=plt.cm.gray(0.1), alpha=0.5) 
plt.hist(b, linestyle='--' ,color=plt.cm.gray(0.4), alpha=0.5) 
plt.hist(c, linestyle='solid', color=plt.cm.gray(0.8), alpha=0.5) 

enter image description here