0

Some time ago I asked how to set line style through a function taking the plot axes instance as parameter (matplotlib set all plots linewidth in a figure at once).

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)

As shown above one suggested to use ax.lines in the function, but now I would like to know how to set other properties such as marker properties, colors ...

1 Answer 1

2

You can find information about the setting the properties of Lines2D here. Marker size and marker color can be set similarly to the line width:

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()
Sign up to request clarification or add additional context in comments.

2 Comments

what about setting legend items font size?
@user1850133 Please ask a new question if you have new issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.