1

How can I import matplotlib pyplot options as dict?

import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(1,100,100)
plt.plot(x,x*x,color=np.random.rand(3,1),linewidth=2)

I would like to covert the last command as:

str1={'color':np.random.rand(3,1),'linewidth':2}
plt.plot(x,x*x,str1)

It doesn't have to be a dictionary. Any format will be fine. I hate to have to keep typing, but I also don't want to set it permanently. Thanks.

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
Aung
  • 443
  • 5
  • 15

1 Answers1

1

This should work:

plt.plot(x, x*x, **str1)

For more information on the dictionary expansion operator, check out this answer.

Community
  • 1
  • 1
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119