matplotlib通过函数设置打印属性

matplotlib通过函数设置打印属性,matplotlib,Matplotlib,不久前,我问过如何通过一个函数设置线条样式,该函数以plot Axis实例为参数 () 如上所示,有人建议在函数中使用ax.lines,但现在我想知道如何设置其他属性,如标记属性、颜色…您可以找到有关设置Lines2D标记大小和标记颜色属性的信息,这些属性的设置与线宽类似: import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10

不久前,我问过如何通过一个函数设置线条样式,该函数以plot Axis实例为参数 ()


如上所示,有人建议在函数中使用ax.lines,但现在我想知道如何设置其他属性,如标记属性、颜色…

您可以找到有关设置Lines2D标记大小和标记颜色属性的信息,这些属性的设置与线宽类似:

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

设置图例项目字体大小如何?@user1850133如果有新问题,请提出新问题。
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()