pythonpython-3.xjupyter-notebookvoilabqplot

How to remove scientific notation on bqplot?


I am using bqplot to create a live line graph on jupyter-notebook + VOILA

from bqplot import pyplot as plt2
import datetime

x_values = []  #array of datetimes
y_values = []  #array of 10+ digit numbers
plt2.show()

def functionThatIsCalledRepeatedly(x_val, y_val):
    x_values.append(x_val)
    y_values.append(y_val)
    plt2.plot(x_values, y_values)

Part of the Resulting Plot

My question is, how do I remove the scientific notation from the y-axis. It's a simple task but I have tried a lot of things.

I tried using axes.tick_format property of the graph but I think that only works if you have axes objects which I cannot have because they require the mandatory Scale property which I cannot use because the graph is live and the x and y scales need to be generated/recalibrated while it runs.

I tried changing y_values.append(y_val) to y_values.append("{:.2f}".format(y_val)) but that converts to a string and bqplot doesn't process it as a number so it ends up with negative numbers on top of the 0 sometimes.

I tried converting to a numpy array and then doing np.set_printoptions(suppress=True) which (obviously) didn't work.

Basically tried a lot of things and I think it comes down to some bqplot property that may or may not exist. Have been stuck for a while. Thank you!


Solution

  • You can provide axes options with the tick format you want to the plot method:

    plt2.plot(x_values, y_values, axes_options={
        y=dict(tick_format='0.2f')
    })
    

    You can see examples of this axes_options (using a scatter plot, but that should work the same) in this notebook: https://github.com/bqplot/bqplot/blob/master/examples/Marks/Pyplot/Scatter.ipynb