2

I am plotting a large number of plots and am using consistent marker styles, but more than one style. I am looking for a way to define the different markers I want to use once - and then just call the relevant marker for each plot. Consider

import matplotlib.pyplot as plt
import numpy as np

a = np.random.rand(50)
b = np.random.rand(50)
c = np.random.rand(50)
x = np.random.rand(50)

plt.plot(x,a, 'o', markeredgecolor = 'b', markerfacecolor = 'b')
plt.plot(x,b, 's', markeredgecolor = 'xkcd:amber', markerfacecolor = 'xkcd:amber')
plt.plot(x,c, '<', markeredgecolor = 'r', markerfacecolor = 'r')

I would like a way to have something like

marker1 = {'o', markeredgecolor = 'b', markerfacecolor = 'b'}
marker2 = {'s', markeredgecolor = 'xkcd:amber', markerfacecolor = 'xkcd:amber'}
marker3 = {'<', markeredgecolor = 'r', markerfacecolor = 'r'}
plt.plot(x,a,marker1)
plt.plot(x,b,marker2)
plt.plot(x,c,marker3)

I want to create a series of different markers (or line styles etc.) and call them by a variable name. I do not want to change the global settings. I have more characteristics than just those in the example.

I don't know what this is called, so searching for a solution has been rather unsuccessful - apologies if this has been asked and answered already.

1 Answer 1

1

Put your marker options into a dictionary, and then unpack it, like that:

marker1 = {'marker': 'o', 'markeredgecolor': 'b', 'markerfacecolor': 'b'}
marker2 = {'marker': 's', 'markeredgecolor': 'xkcd:amber', 'markerfacecolor': 'xkcd:amber'}
marker3 = {'marker': '<', 'markeredgecolor': 'r', 'markerfacecolor': 'r'}

plt.plot(x, a, **marker1)
plt.plot(x, b, **marker2)
plt.plot(x, c, **marker3)
Sign up to request clarification or add additional context in comments.

Comments

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.