Welcome folks today in this blog post we will be generating random color
with hexadecimal code using matplotlib
and random
library in python. All the full source code of the application is given below.
Get Started
In order to get started we need to install the following library using the below command as shown below
pip install matplotlib
pip install random
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 |
import matplotlib.pyplot as plt import random number_of_colors = 8 color = ["#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(number_of_colors)] print(color) for i in range(number_of_colors): plt.scatter(random.randint(0, 10), random.randint(0,10), c=color[i], s=200) plt.show() |
Now execute the python
script by typing the below command as shown below
python app.py