Nicolas Chaparro
Nicolas Chaparro

Reputation: 1

Issue with color treemap

I'm new here. i have a problem with this code with the color scale: some high values have red color and others have green, but the idea is the negative values were red and positive green.

range_color = [min_value, max_value]
fig = px.treemap(datos, 
                    path=['Todos','Sector','Empresa'],
                    values=valores, color='PcChangeDay',  # Usamos PcChangeDay para el color
                    color_continuous_scale=['Red', "#8b0000", 'Green'],
                    range_color=range_color,
                    hover_data={'Empresa': True, 
                                     'PcChangeDay': True,
                                     'DailyRange': True,
                                     'CloseToLowRatio': True,
                                     'CloseToHighRatio': True,
                                     'VWAP': True,
                                     'TotalVolume': True})

        # Customizar el hovertemplate para que muestre solo los datos deseados
hovertemplate = '<b>%{customdata[0]}</b><br>' + \
                        'PcChangeDay: %{customdata[1]:f}%<br>' + \
                        'Daily Range: %{customdata[2]:.2f}<br>' + \
                        'Close to Low Ratio: %{customdata[3]:.2f}<br>' + \
                        'Close to High Ratio: %{customdata[4]:.2f}<br>' + \
                        'VWAP: %{customdata[5]:.2f}<br>' + \
                        'Total Volume: %{customdata[6]:,.0f}<br>' + \
                        '<extra></extra>'

fig.update_traces(hovertemplate=hovertemplate, 
                        customdata=datos[['Empresa', 'PcChangeDay','DailyRange', 'CloseToLowRatio', 'CloseToHighRatio', 'VWAP', 'TotalVolume']].values,
                        textposition="middle center", 
                        selector=dict(type='treemap'), 
                        marker=dict(cornerradius=5))

fig.update_layout(margin=dict(t=30, l=20, r=10, b=10))
fig.update(layout_coloraxis_showscale=True)

        # Mostrar el gráfico
fig.show()

It means that the negative values ​​have to be in red and the positive ones in green, but some are in red and others are not, just like the positive ones that should be in green, only some are in green and others in red.

Upvotes: 0

Views: 24

Answers (0)

Related Questions