Hi everyone, Today I will show you how to color your plot.
Marker Edge Color
You can use the keyword argument markeredgecolor
or the shorter mec
to set the color of the edge of the markers
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 1, 2, 3, 5, 6])
ypoints = np.array([0, 1, 2, 3, 5, 6])
plt.plot(xpoints, ypoints, marker='o', markeredgecolor='r')
plt.show()
That will generate the following output
For the value of color, you can use basic color code such as:
-
b
: blue -
g
: green -
r
: red -
c
: cyan -
m
: magenta -
y
: yellow -
k
: black -
w
: white
Other than basic value, you can use hex code and color codes from the color names supported by all browsers https://www.w3schools.com/colors/colors_names.asp
Marker Face Color
You can use the keyword argument markerfacecolor
or the shorter mfc
to set the color inside the edge of the markers
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 1, 2, 3, 5, 6])
ypoints = np.array([0, 1, 2, 3, 5, 6])
plt.plot(xpoints, ypoints, marker='o', markerfacecolor='r')
plt.show()
Which will produces the following output
For color value you can refer to the available color value for the Marker Edge Color above.
Line Color
You can use the keyword argument color
or the shorter c
to set the color of the line
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.arange(10)
plt.plot(ypoints, color='r')
plt.show()
Which will produce the following output
That is how you can customize the color of your plot. Thank you for reading and have a nice day!
Top comments (0)