Error bars using plot_pandas_GUI()
¶
You can try this notebook live by lauching it in Binder.This can take a while to launch, be patient. .
First we import pandas
, pandas_GUI
plus numpy
, and create some data. In this case a noisy sine wave.
import pandas as pd
from pandas_GUI import *
import numpy as np
X = [k*np.pi/10 for k in range(-30,30)]
Y = 98*np.sin(X)+np.random.default_rng().normal(0,3,60)
df = pd.DataFrame({'X':X, 'Y':Y})
Default plot of the data set¶
This is the plot made using the default settings of plot_pandas_GUI()
. See step-by-step example.
# CODE BLOCK generated using plot_pandas_GUI().
# See https://jupyterphysscilab.github.io/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_1 = go.FigureWidget(layout_template="simple_white")
# Trace declaration(s) and trace formatting
scat = go.Scatter(x = df['X'], y = df['Y'],
mode = 'lines', name = 'Noisy Sine Wave',)
Figure_1.add_trace(scat)
# Axes labels
Figure_1.update_xaxes(title= 'X')
Figure_1.update_yaxes(title= 'Y')
# Plot formatting
Figure_1.update_layout(title = 'Noisy Sine Wave Default Plot', template = 'simple_white', autosize=True)
Figure_1.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 1: This should display a live plotly plot that can be zoomed and show point values upon hovering. If you do not see a live plot the notebook is not running or trusted. Click on the 'Not Trusted' button in the Jupyter menu bar to trust the notebook.
Displaying Error Bars¶
Rather than using the default plot options, before adding a trace to the plot you can customize how it will be displayed.
- After choosing what data trace to plot you expand the "Optional (Trace formatting, error bars...)" section by clicking on it.
- See example trace formatting options for more information. We will use markers rather than lines for demonstrating error bars for the remainder of this example.
- X or Y error bars may be shown. As the options are the same for both this example will only demonstrate Y error bars.
An image of the expanded Y error bars section is shown below.
The choices in the Error Type
dropdown are:
none
, the default which displays no error bars.percent
, which displays error bars that are a fixed percent of the value. The percentage is entered in the% or constant
box. Make sure to click outside the box to force setting of the percentage.constant
, which displays error bars of a constant size. The constant is entered in the% or constant
box. Make sure to click outside the box to force setting of this constant value.data
, which displays error bars of a size specified in a column chosen from the same dataframe as the trace. The column is chosen using theError values
dropdown.
The plots below show views with the different error bar options.¶
Percent error bars¶
# CODE BLOCK generated using plot_pandas_GUI().
# See https://jupyterphysscilab.github.io/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_2 = go.FigureWidget(layout_template="simple_white")
# Trace declaration(s) and trace formatting
scat = go.Scatter(x = df['X'], y = df['Y'],
mode = 'markers', name = 'Noisy Sine Wave',
error_y_type='percent', error_y_value=5.0,)
Figure_2.add_trace(scat)
# Axes labels
Figure_2.update_xaxes(title= 'X', mirror = True)
Figure_2.update_yaxes(title= 'Y', mirror = True)
# Plot formatting
Figure_2.update_layout(title = 'Example of Percent Error Bars', template = 'simple_white', autosize=True)
Figure_2.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 2: Example of percent
error bars. In this case they are 5% of $\left |{Amplitude} \right |$.
Constant error bars¶
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_3 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = df['X'], y = df['Y'],
mode = 'markers', name = 'Noisy Sine',
error_y_type='constant', error_y_value=5.0,)
Figure_3.add_trace(scat)
Figure_3.update_xaxes(title= 'Time', mirror = True)
Figure_3.update_yaxes(title= 'Amplitude', mirror = True)
Figure_3.update_layout(title = 'Example of Constant Error Bars', template = 'simple_white')
Figure_3.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 3: Examples of the constant
error bars ($\pm5$).
Error bars from data¶
We start by adding a column of random numbers with a standard deviation of 10 to our dataframe. Then choose that column as our errors.
df['error']=np.random.default_rng().normal(0,10,60)
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_4 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = df['X'], y = df['Y'],
mode = 'markers', name = 'Noisy Sine',
error_y_type='data', error_y_array=df['error'],)
Figure_4.add_trace(scat)
Figure_4.update_xaxes(title= 'Time', mirror = True)
Figure_4.update_yaxes(title= 'Amplitude', mirror = True)
Figure_4.update_layout(title = 'Example of error bars from data', template = 'simple_white')
Figure_4.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 4: Example of error bars using the data
choice. It may be easier to see the variation if you zoom in on a region.
Learn More¶
In addition to trying it below if this is a live notebook, you can look at the other examples listed in the Pandas GUI website.
Try It¶
If you are running this notebook live in binder you can try it here by running the first cell to import the tools and data. Then run the cell below to create the GUI. Note: You may want to expand the collapsed instructions to learn more about each tab.
plot_pandas_GUI()