Repository navigation
enable arbitrary formatting on x-axis and y-axis tick labels #4041
Description
Activity
The need for what you're asking for is very clear and your proposal makes a lot of sense from the Python developer's perspective but unfortunately this would be extremely challenging with the current architecture, as no Python code can be executed while a figure is being rendered...
update_layout()and all other Python functions exclusively populate static JSON objects which are passed to Plotly.js for browser-side processing, so there would be no way for such a function to execute, and for security reasons the Plotly.js system cannot accept workaround such as stringified Javascript function in such a place either. We're basically left with the kind of formatting mini-language that we have right now, which we can/should expand to meet various missing formatting needs.Regarding bolding, this is also something which is missing from Plotly.js' formatting concept at the moment. We have font family and font size but not font weight in the data model, although this could be added globally to all text objects I think. Conditional bolding, much like conditional coloring of something like tick text would need to work a bit differently however.
+1 for this kind of a feature. I came a cross a task recently where I needed to create custom format for tick values. I ended up just creating a fixed set of tick values manually but that killed the dynamic nature of the plot's ticks when zooming in on the plot which is a major drawback of my solution.
Just for a note, the task was to create a secondary y axis ticks which would be proportional to the primary y axis ticks with a custom proportion function (something like
lambda x = 1 - x / some_constatnt).Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson
@gvwilson yes, it is still a concern, see my previous comment right above yours
- changed the title
[-]Feature Request: Arbitrary formatting on x-axis and y-axis tick labels[/-][+]enable arbitrary formatting on x-axis and y-axis tick labels[/+]on Aug 12, 2024 Hi @pmantica3 @sergei3000 I'm just following up on some old issues — as noted above, we're unlikely to implement this request in the form of passing a Python function, since that would be incompatible with the existing plotting pipeline which happens entirely in JavaScript in the browser.
However, something like
ticktemplatealong the lines ofhovertemplate/texttemplatecould possibly be implemented. It would have to be added inplotly.jsthough. I suppose that API would look something like:ticktemplate="<b>%{y}x</b>"
Also, just a note that it's now possible (as of plotly/plotly.js#6990) to make tick labels bold, by setting
tickfont.weightto 1000 (or any other number 1-1000, though not all fonts support all intermediate weights).You can also append a suffix to all tick labels using
ticksuffix(for whatever reason,ticksuffixis ignored whentickvalsis provided, but you can usetick0anddtickinstead).So you can get your desired outcome by using:
fig.update_layout( yaxis = dict( tick0 = 1, dtick = 1, ticksuffix = "x", tickfont = dict(weight=1000) ) )
I'll leave this issue open for now though to track a desire for easier and more flexible tick formatting options.
Thanks for the awesome work on this project! It is incredibly useful!
I have a feature request. I work for a hedge fund and we want our plotly graphs to follow a standardized format. I am having a hard time through writing a generic formatting function that formats the x-axis and y-axis tick values.
For instance, if you wanted to set the tick axis to be bold and include a "x" at the end, you would need to do something like:
Which is pretty inconvenient because you have to specify the tickvals every time you want to do this.
So I was thinking that it could be a good idea to add something like:
fig.update_xaxis(tick_text_formatter=<function that formats a tick value>)Thoughts?
Again, thanks for the awesome work!