Is there a bug or issue with the text_auto argument for Plotly Express bar charts?
This has happened before, so I am assuming other had similar issues. It does not work no matter what I do, whether I set it to True (boolean) or give it a text directive. I have reviewed the documentation. If there is a workaround, can you point me in the right direction? I really want to use labels with this chart.
it’s hard to say without a minimal working example. Can you please share data and code of a basic bar chart where the text_auto does not work properly. Thank you,
My apologies. I worked on this all day yesterday, and I was in a rush to yoga class last night when I asked the question.
I try not to be sloppy with my communications, but I am not exaggerating when I say I spent at least ten hours yesterday trying to generate an interactive chart that adjusts to changes in user input. The answer is always simple and obvious in retrospect, but I pulled my hair out climbing the learning curve.
Ultimately, I think I solved the mystery.
I will explain what I found in detail in case it helps someone in the future.
I found you must run Plotly 5.5 for text_auto to work on any chart. For some reason, I was running 5.4 which caught me by surprise because I installed it only weeks ago.
To resolve the issue, I had to use this command: pip install plotly==5.5. if I ran pip install plotly, without specifying the version, it will still install 5.4 as of this morning.
Once I had installed 5.5, the text_auto argument works, but it only works in Plotly Express charts, where “px.bar” is used to draw the figure. See Bar Charts with Text in the documentation for an example.
I needed a chart like Bar Chart with Relative Barmode (in the same documentation), because I need to compare the final results to nutritional benchmarks. Instead of “px.bar,” it requires “fig = go.Figure()” to draw the chart. It does not accept the “text_auto” argument with producing this error message:
ValueError: 'NoneType' object is not subscriptable
Invalid value received for the 'text' property of bar
The 'text' property is a string and must be specified as:
- A string
- A number that will be converted to a string
- A tuple, list, or one-dimensional numpy array of the above
Property does not support subscripting:
Fortunately, the graph entitled “Rotated Bar Chart Labels” in the documentation should not only enable me to use labels, but it also includes the “barmode=‘group’” argument that should allow me to compare actual levels to benchmarks.
I have not tried it yet, but it should meet my needs.
If you have any pointers or corrections, I would love to hear them.
If you still want a working example, please let me know.
Again, my apologies for the messy question.
For some reason upgrading to 5.10.0 required a full jupyter lab service reboot instead of just a kernel reset in order to get
text_auto working for my heatmaps