Plotly: How to assign specific colors for categories? [duplicate]
2024/10/11 9:24:06
I have a pandas dataframe of electricity generation mix. So it consists of electricity generation by different fuels. I want to assign a specific color to a specific fuel.
In Matplotlib, it is convenient to assign a specific color to a specific category by passing a list of colors, e.g.
df.plot(kind="bar",color=["red","green","yellow"]
I wasn't able to assign color similarly for plots using Plotly. What would be the best way to assign specific color to specific categories in Plotly?
Answer
If you're aiming to assign a specific color to a specific fuel then color_discrete_sequence may work just fine for you as long as the structure of your dataset never changes. But the way to specify a color per category is best done through:
For other options please take a look at Plotly: How to define colors in a figure using plotly.graph_objects and plotly.express?? There you will find how to change the color sequence to whatever you want and still specify som exceptions through color_discrete_map.
I have a class with various methods. I have a method in that class something like :class MyClass:async def master_method(self):tasks = [self.sub_method() for _ in range(10)]results = await asyncio.gath…
I am trying to implement word2vec model and getting Attribute error AttributeError: type object Word2Vec has no attribute load_word2vec_formatBelow is the code :wv = Word2Vec.load_word2vec_format("…
This question already has answers here:Getting processor information in Python(12 answers)Closed 8 years ago.Im trying to find out where this value is stored in both windows and osx, in order to do som…
Please help me find my misunderstanding.I am writing an RPG on App Engine. Certain actions the player takes consume a certain stat. If the stat reaches zero the player can take no more actions. I start…
Which one of these is faster? Is one "better"? Basically Ill have two sets and I want to eventually get one match from between the two lists. So really I suppose the for loop is more like:f…
I have a csv file in the form "...","...","..."... with over 40 columns.
When I used this simple code, it only gives me one massive key. Ive been messing with it for over …
I have a large 2D array that I would like to declare once, and change occasionnaly only some values depending on a parameter, without traversing the whole array. To build this array, I have subclassed …
I am new to NetworkX. Right now, I manage to connect all the nodes to this particular node. What I want to do next it to make it interactive e.g. able to make each of the node move by dragging using cu…
I have a dataframe like below:dateTime Name DateTime day seconds zscore
11/1/2016 15:17 james 11/1/2016 15:17 Tue 55020 1.158266091
11/1/2016 13:41 james 11/1/2016 13:41 Tue 4926…
When trying to use pyttsx3 I can only use English voices. I would like to be able to use Dutch as well.
I have already installed the text to speech language package in the windows settings menu. But I …