Display Error of Plotly Express Imshow & Bar Polar

Hey, Guys!
I have a bug with displaying two Plotly graphs. Using Plotly 5.20.0.
If u want to test, please, here is my data
Thanks!

image

First of all, this is a heat map. As you can see in data, the column ‘ВЭД’ has the filled value only in one date - in January 2023th. However after plotting, this filled value is “smeared” all over the dates by an unknown logic. The rest of NaN - data is processed correctly.

And second is Bar Polar.

A number of values are simply just not displayed on the polar chart, although they are currently in dataframe in the current date.

image

Moreover, if I pass a dataframe filtered by date, then all the filled values will be displayed on the chart. However, with multiple animation frames, they are just skipped. And not only for one date, but also for all dates.

Why is that? Can you fix it?
Thx.

Please post your code instead of image so we can try to find your problem.

Sure!

import pandas as pd
import plotly.express as px

# merged_df = pd.read_excel('https://github.com/ThrallPraudmur/ThrallPraudmur/blob/main/to_plotly_community.xlsx')
merged_df = pd.read_excel('to_plotly_community.xlsx')

fig = px.imshow(merged_df.pivot_table(index = 'Продукт', columns = 'Дата комментария', values = 'label'), 
                color_continuous_midpoint = 0,
                color_continuous_scale = ['red', 'green'], 
                template = 'plotly_dark',
                # origin = 'lower'
               )

# fig.update_layout(showlegend = False)
fig.update_layout(margin=dict(t=10, b=10, r=10, l=10))
fig.update_layout(paper_bgcolor = 'rgba(0,0,0,0)', font_color = 'white', plot_bgcolor = 'rgba(0,0,0,0)', coloraxis_showscale = False)
fig
data_copy = merged_df.copy()
data_copy['Дата комментария'] = data_copy['Дата комментария'].apply(lambda x: str(x))
data_copy['label'].replace({-500: 500}, inplace = True)
category_order = ['Депозит', 'Кредит', 'РКО', 'Лизинг', 
                  # 'Факторинг', 'Эквайринг',
                  'ЗПП', 'Страхование', 
                  # 'ВЭД', 
                  'Продукты', 'Финансирование'
                 ]

fig = px.bar_polar(data_copy.fillna(0), 
                   r = 'label', # Values are used to position marks along the radial axis in polar coordinates
                   theta = 'Продукт', #Values are used to position marks along the angular axis in polar coordinates
                   category_orders = {'Продукт': category_order},
                   color = 'Отношение', 
                   animation_group = 'Отношение', animation_frame = 'Дата комментария',
                   template = 'plotly_dark',
                   hover_data = {'Дата комментария': False, 'Отношение': False, 'Продукт': False, 'label': False},
                   hover_name = 'Комментарий',
                   # color_discrete_sequence= ['red', 'green'] # В том порядке, что встречается в данных
                   color_discrete_map = {'Интерес': 'green', 'Не актуально': 'red'}
                  )

fig['layout'].pop('updatemenus') # optional, drop animation buttons
fig.update_layout(showlegend = False,
                  polar = dict(radialaxis = dict(showticklabels = False)),
                  paper_bgcolor = 'rgba(0,0,0,0)', font_color = 'white')
fig.show()

With the first one, I think you can use insiderange when update xaxes.

merged_df = pd.read_excel('to_plotly_community.xlsx')
#merged_df2 = pd.pivot_table(index = 'Продукт', columns = 'Дата комментария', values = 'label', aggfunc=np.sum).reset_index()

fig = px.imshow(merged_df.pivot_table(index = 'Продукт', columns = 'Дата комментария', values = 'label'), 
                color_continuous_midpoint = 0,
                color_continuous_scale = ['red', 'green'], 
                template = 'plotly_dark',
                # origin = 'lower'
               )

# fig.update_layout(showlegend = False)
fig.update_layout(margin=dict(t=10, b=10, r=10, l=10))
fig.update_layout(font_color = 'white', plot_bgcolor = 'rgba(0,0,0,0)', coloraxis_showscale = False)
fig.update_xaxes(insiderange=[merged_df['Дата комментария'].min(), merged_df['Дата комментария'].max()])
fig.show()

For the second one, can’t reproduce the same as your image so I’m not sure about that.

Couldn’ t reproduce :frowning:

ValueError: Invalid property specified for object of type plotly.graph_objs.layout.XAxis: 'insiderange'
Did you mean "fixedrange"?

With the second one, yes, some trouble with datetime-format, fixed…

data_copy = merged_df.copy()
data_copy['Дата комментария'] = data_copy['Дата комментария'].apply(lambda x: str(x))
data_copy['label'].replace({-500: 500}, inplace = True)
category_order = ['Депозит', 'Кредит', 'РКО', 'Лизинг', 
                  # 'Факторинг', 'Эквайринг',
                  'ЗПП', 'Страхование', 
                  # 'ВЭД', 
                  'Продукты', 'Финансирование'
                 ]

fig = px.bar_polar(data_copy.fillna(0), 
                   r = 'label', # Values are used to position marks along the radial axis in polar coordinates
                   theta = 'Продукт', #Values are used to position marks along the angular axis in polar coordinates
                   category_orders = {'Продукт': category_order},
                   color = 'Отношение', 
                   animation_group = 'Отношение', animation_frame = 'Дата комментария',
                   template = 'plotly_dark',
                   hover_data = {'Дата комментария': False, 'Отношение': False, 'Продукт': False, 'label': False},
                   hover_name = 'Комментарий',
                   # color_discrete_sequence= ['red', 'green'] # В том порядке, что встречается в данных
                   color_discrete_map = {'Интерес': 'green', 'Не актуально': 'red'}
                  )

fig['layout'].pop('updatemenus') # optional, drop animation buttons
fig.update_layout(showlegend = False,
                  polar = dict(radialaxis = dict(showticklabels = False)),
                  paper_bgcolor = 'rgba(0,0,0,0)', font_color = 'white')
fig.show()

You can check it here: Axes in Python

I’m using 5.18.0 and it worked well.

Oh, I see…
Thank you!