2014-04-01 44 views
0

前一段時間,我問了如何通過以繪圖軸實例爲參數 (matplotlib set all plots linewidth in a figure at once)的函數設置線條樣式。matplotlib通過函數設置繪圖屬性

import matplotlib.pyplot as plt 
import numpy as np 
fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(range(10)) 
ax.plot(2 * range(10)) 

solution suggested: 
def bulk_lw_edjuster(ax, lw = 5) 
    for ln in ax.lines: 
    ln.set_linewidth(lw) 

如上圖所示一個建議的功能使用ax.lines,但現在我想知道如何設置其他屬性,如標記性質,顏色...

回答

2

你可以找到信息關於設置Lines2D here.的屬性標記尺寸和標記顏色可以設置與線寬類似:

import matplotlib.pyplot as plt 
import numpy as np 
fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(range(10)) 
ax.plot(2 * range(10)) 

#solution suggested: 
def bulk_lw_edjuster(ax, lw = 5, markersize = 5, markerfacecolor = 'r'): 
    for ln in ax.lines: 
     ln.set_linewidth(lw) 
     ln.set_markersize(markersize) # set marker size 
     ln.set_markerfacecolor(markerfacecolor) # set marker color 

# Change the plot properties.   
bulk_lw_edjuster(ax, lw =10, markersize = 10, markerfacecolor = 'm') 
plt.show() 
+0

設置圖例項目字體大小怎麼樣? – user1850133

+0

@ user1850133如果您有新問題,請提出一個新問題。 – tacaswell