Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: plot changing float values as colours

I have a list of of tuples of three colors:

v = ([0.16091847477176702, 0.4337815920028113, 0.40529993322542174)
(0.15019057645364922, 0.40486281920262385, 0.44494660434372696)
(0.14017787135673926, 0.44453863125578225, 0.4152834973874785)
(0.13083267993295664, 0.41490272250539673, 0.45426459756164661)
(0.17697859494133705, 0.36303988219222216, 0.45998152286644078)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.15406618756053894, 0.37407489744412198, 0.47185891499533911)
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723)
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723)
(0.17349860310102702, 0.34763847852469609, 0.47886291837427691)
(0.16193202956095856, 0.39112924662304965, 0.44693872381599176)]

Each value in the tuple I untuitively interpret as a color (for example: how yellow, how red, how blue), so together each tuple gives me a colour (as the mix of the first one, second and third one). Is it possible to plot the change of the colors using matplotlib? My initial idea was to use RGB, but RGB takes integers, and the precision of those number is quite important. Does anyone has any suggestions?

like image 285
Ziva Avatar asked Aug 14 '26 07:08

Ziva


1 Answers

floats between 0 and 1 are good values for rgb in matplotlib. here's a small example

import numpy as np
import matplotlib.pyplot as plt

v = [(0.16091847477176702, 0.4337815920028113, 0.40529993322542174),
(0.15019057645364922, 0.40486281920262385, 0.44494660434372696),
(0.14017787135673926, 0.44453863125578225, 0.4152834973874785),
(0.13083267993295664, 0.41490272250539673, 0.45426459756164661),
(0.17697859494133705, 0.36303988219222216, 0.45998152286644078),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.15406618756053894, 0.37407489744412198, 0.47185891499533911),
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723),
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723),
(0.17349860310102702, 0.34763847852469609, 0.47886291837427691),
(0.16193202956095856, 0.39112924662304965, 0.44693872381599176)]

y = np.arange(len(v))
for i in range(len(v)):
    plt.plot(y[i], 0, marker='o', ls='', c=v[i], markersize=20)

plt.show()

and the result:

enter image description here

it's subtle but it works

like image 74
bobrobbob Avatar answered Aug 16 '26 23:08

bobrobbob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!