PYPLOT Defining a marker shape in Python with a variable

Viewed 43

So an exemplar format would be:

plt.plot([1],[1],'rs')

In this circumstance the marker would be a red square, however, I'm not sure how to do this with a defined variable (ex: markershape = 's')

1 Answers

Use f-Strings for this and it's pretty simple and easy too.

>>> markershape = 's'
>>> plt.plot(np.arange(10), f'r{markershape}')

enter image description here

In fact you can do it with most of the stuff. Like with color and markershape as well:

>>> color = 'g'
>>> markershape = 'v'

>>> plt.plot(np.arange(10), f'{color}{markershape}')

enter image description here

Related