sarvenaz
sarvenaz

Reputation: 11

python Error: cannot convert argument to rgb sequence

this is my code:

    import numpy as np
    import matplotlib.pyplot as plt
    a=[0.8358042069314231, 0.6024065701024207, 0.9617569162444223, 1.120885517331551, 0.9778266035872442, 0.8887086644135614, 1.129697816341799, 0.7201744522139227, 0.8664407952949176, 0.7341260712316454, 0.658510937374308, 0.8904146773410425, 0.8717757176749454, 0.8166459824393625, 0.8339372675079395, 0.8003634701144817, 0.7659874150298758, 0.588331305578084, 0.55522301812699, 1.170550069401354, 0.8591871445132889, 0.8791241895935374, 1.025333128737861, 0.7626055728517448, 1.078399671082715, 0.7055734855725923, 0.720798713206163, 0.6886333276632871, 0.8471288388621045, 0.8754780670153172, 0.8523708462663552, 0.7246874496850487, 0.8292394046416274, 0.7803767971215964, 0.8743477112471153, 0.9958969069407901, 0.6769431631803139, 0.8773467224566912, 1.000147098676991, 0.7696909697871333, 0.8737321588069848, 0.5382244141057999, 0.4713278235703561, 0.6646682699231433, 0.8142396110707529, 0.8010456498519396, 0.6230657827339223, 0.688395869330359, 0.9462232919128286, 0.8495316484723737, 0.9942093060309608, 0.5228577377120195, 0.8192451490174453, 0.7218109597938437, 1.094902533752046, 0.7918411571432902, 0.1853703245133316, 0.6526308267023782, 1.170724769758224, 0.7302772774120317, 0.9324328310595102, 0.4962678697988561, 0.3752720253093461, 1.071244603207015, 0.66615740139685, 1.403488959177528, 0.6038971390943845, 0.8096930613194361, 0.9225707844751444, 0.4648132597838837, 0.783465976417999, 0.587824043205004, 0.8696348536547795, 0.6087662565833588, 0.8114405187405719, 1.160979540670139, 0.4172098683725269, 0.8203049559312928, 0.5283513301434342, 0.9804213471244552, 0.8612093808286192, 0.9541602042466272]
aa=[0.5467142240969229, 0.9832349591334052, 0.6237246993961033, 0.0, 0.5831794244764199, 0.3514226975000825, 1.77109168097854, 0.6247138549785067, 1.664771783798592, 0.4247971724813068, 0.0, 0.2523393191582641, 0.4893039208326278, 0.9281078151898693, 0.5768011081148378, 1.108193038745785, 0.2456363621402149, 0.8617850242006354, 0.5267724873577896, 0.1577668980710197, 0.3256065201760527, 0.6198844334464519, 0.0, 0.4800467231453376, 0.41063682727516, 0.5888128461522766, 0.7914054193752765, 0.5364683892414501, 0.6300029971600053, 0.795956524973436, 0.8859314844820457, 0.0, 1.009933346883598, 0.3681143616052806, 0.673066247323437, 0.784823895306669, 0.6549928032683661, 0.6270061214399052, 1.15337367807155, 0.5136022829838987, 0.6315411393786611, 0.3271570452075644, 0.5957190842140955, 0.0, 0.4745979810598814, 0.305842741616707, 0.3842636886080335, 0.7196084371435851, 0.0, 0.312272760281443, 0.3554478389969122, 0.868091699158965, 0.5869574668164317, 0.5649192923746441, 0.0, 0.8057386703802037, 0.0, 0.501235379563183, 0.6103368504256358, 0.5247345586856612, 0.8227552208451726, 0.1186217840874107, 0.0, 0.0, 0.0, 1.063407586906356, 0.6192493545908646, 0.0, 0.8068052574049874, 0.3638468406214595, 0.9188082415772201, 0.5535302027459117, 1.204703404116142, 0.0, 0.6159298413053304, 2.113067884469592, 0.0, 0.8735339653162774, 0.5949939082731295, 0.0, 0.7042802775180598, 0.7582877313150294]
aaa=[27114, 25347, 25839, 23503, 25181, 27094, 23412, 27132, 25751, 23270, 24659, 25522, 25412, 24696, 24667, 23323, 23206, 24794, 26535, 26074, 25354, 24446, 25871, 25283, 25387, 26820, 24011, 23982, 24237, 26169, 24146, 25186, 25122, 25223, 23715, 24000, 24876, 23920, 24256, 26191, 24873, 23603, 27226, 24253, 25157, 25099, 24860, 23125, 25348, 25696, 24563, 25866, 24910, 27009, 25067, 27643, 23798, 28002, 27531, 25525, 25126, 24050, 24040, 24467, 25819, 25935, 25453, 25886, 26827, 26372, 26465, 24786, 24275, 26212, 23968, 29389, 23460, 26550, 25241, 24205, 24649, 24121, 24734, 24221, 26176, 24077, 27017, 22919, 24376, 25579, 24076, 28658, 26675]
plt.scatter(a,aa,color=aaa)
plt.colorbar()
plt.show()

I got this error:

ValueError: to_rgba: Invalid rgba arg "27114"
to_rgb: Invalid rgb arg "27114"
cannot convert argument to rgb sequence

how could i add colorbar with third data?

Upvotes: 0

Views: 1868

Answers (1)

Syncrossus
Syncrossus

Reputation: 626

Your variable aaa doesn't define matplotlib colors. From the documentation :

Matplotlib recognizes the following formats to specify a color:

  • an RGB or RGBA tuple of float values in [0, 1] (e.g., (0.1, 0.2, 0.5) or (0.1, 0.2, 0.5, 0.3));
  • a hex RGB or RGBA string (e.g., '#0F0F0F' or '#0F0F0F0F');
  • a string representation of a float value in [0, 1] inclusive for gray level (e.g., '0.5');
  • one of {'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'};
  • a X11/CSS4 color name;
  • a name from the xkcd color survey; prefixed with 'xkcd:' (e.g., 'xkcd:sky blue');
  • one of {'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'} which are the Tableau Colors from the ‘T10’ categorical palette (which is the default color cycle);
  • a “CN” color spec, i.e. 'C' followed by a single digit, which is an index into the default property cycle (matplotlib.rcParams['axes.prop_cycle']); the indexing occurs at artist creation time and defaults to black if the cycle does not include color.

Which means you need to transform your numbers to comply with one of these formats.

Upvotes: 1

Related Questions