Trace formatting 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
and pandas_GUI
, and load some data. In this case we will load two time dependent Laser Induced Fluorescence (LIF) data sets.
import pandas as pd
from pandas_GUI import *
LIF = pd.read_csv('DataSets/LIF.csv')
LIF2 = pd.read_csv('DataSets/LIF2.csv')
Default plot of the two data sets¶
This is the plot made in the step-by-step example.
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_1 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = LIF['time(s)'], y = LIF['Signal (V)'],
mode = 'lines', name = 'LIF1',)
Figure_1.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['Signal (V)'],
mode = 'lines', name = 'LIF2',)
Figure_1.add_trace(scat)
Figure_1.update_xaxes(title= 'Time (s)', mirror = True)
Figure_1.update_yaxes(title= 'Signal (V)', mirror = True)
Figure_1.update_layout(title = 'Figure_1', template = 'simple_white')
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.
# (Making some additional traces so that more options can be shown in one graph.
LIF['T2'] = LIF['Signal (V)'] * 0.2 + 0.01
LIF['T3'] = LIF['Signal (V)'] * 0.2 + 0.02
LIF['T4'] = LIF['Signal (V)'] * 0.2 + 0.03
LIF['T5'] = LIF['Signal (V)'] * 0.2 + 0.035
LIF2['T2'] = LIF2['Signal (V)'] *0.2 +0.005
LIF2['T3'] = LIF2['Signal (V)'] *0.2 +0.01
LIF2['T4'] = LIF2['Signal (V)'] *0.2 +0.015
LIF2['T5'] = LIF2['Signal (V)'] *0.2 +0.02
Trace formatting options¶
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.
- You can adjust the following trace characteristics in the expanded section: color; line styling; line thickness; marker styles; and marker fill.
- Once you have made your choices, you then click on the "Add Trace" button.
- After adding a trace you can change your formatting choice only by manually editing the code or by deleting the code for the particular trace, followed by using the GUI to select it again and then adding it back.
An image of the expanded trace formatting section is shown below.
The options available are a subset of all the plotly options. If you want slightly different format options you can edit the code created by the GUI and run it again.
The plots below illustrate the available trace formatting options.¶
Trace Style¶
# 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 = LIF2['time(s)'], y = LIF2['T2'],
mode = 'lines', name = 'lines',)
Figure_3.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T3'],
mode = 'markers', name = 'markers',)
Figure_3.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T4'],
mode = 'lines+markers', name = 'lines+markers',)
Figure_3.add_trace(scat)
Figure_3.update_xaxes(title= 'Time (s)', mirror = True)
Figure_3.update_yaxes(title= 'Signal', mirror = True)
Figure_3.update_layout(title = 'Trace Style Comparison', template = 'simple_white')
Figure_3.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 2: Example of the lines
, markers
and lines+markers
trace styles. You may find it easier to see the differences if you zoom in.
Line Style¶
# 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 = LIF2['time(s)'], y = LIF2['T2'],
mode = 'lines', name = 'solid',)
Figure_4.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T3'],
mode = 'lines', name = 'dot',
line_dash='dot', )
Figure_4.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T4'],
mode = 'lines', name = 'dash',
line_dash='dash', )
Figure_4.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T5'],
mode = 'lines', name = 'dashdot',
line_dash='dashdot', )
Figure_4.add_trace(scat)
Figure_4.update_xaxes(title= 'Time (s)', mirror = True)
Figure_4.update_yaxes(title= 'Signal', mirror = True)
Figure_4.update_layout(title = 'Line Style Comparison', template = 'simple_white')
Figure_4.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 3: Examples of the solid
, dot
, dash
and dashdot
line styles.
Color¶
If the default
setting is used the colors will be assigned automatically by plotly based on the plot style chosen. Otherwise there are 9 colors to choose from that contrast with each other pretty well (except for not being fully red/green colorblind friendly).
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_5 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = LIF['time(s)'], y = LIF['T2'],
mode = 'lines', name = 'blue',)
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF['time(s)'], y = LIF['T3'],
mode = 'lines', name = 'orange',
line_color = 'orange', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF['time(s)'], y = LIF['T4'],
mode = 'lines', name = 'green',
line_color = 'green', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF['time(s)'], y = LIF['T5'],
mode = 'lines', name = 'purple',
line_color = 'purple', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T2'],
mode = 'lines', name = 'red',
line_color = 'red', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T3'],
mode = 'lines', name = 'gold',
line_color = 'gold', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T4'],
mode = 'lines', name = 'brown',
line_color = 'brown', )
Figure_5.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T5'],
mode = 'lines', name = 'black',
line_color = 'black', )
Figure_5.add_trace(scat)
Figure_5.update_xaxes(title= 'Time (s)', mirror = True)
Figure_5.update_yaxes(title= 'Signal', mirror = True)
Figure_5.update_layout(title = 'Available Colors', template = 'simple_white')
Figure_5.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 4: Available color choices.
Markers¶
Markers can be either solid or unfilled. You can specify the marker color, but this GUI only supports the same fill and marker color. You can edit the generated code to have a fill color different from the marker outline color.
# Create some short data sets to show the marker choices.
marker = pd.DataFrame({'X':[i for i in range(0,1)],
'Y1':[i/2 for i in range(0,1)],
'Y2':[i/2 + 0.2 for i in range(0,1)],
'Y3':[i/2 + 0.4 for i in range(0,1)],
'Y4':[i/2 + 0.6 for i in range(0,1)],
'Y5':[i/2 + 0.8 for i in range(0,1)],
'Y6':[i/2 + 1 for i in range(0,1)],
'Y7':[i/2 + 1.2 for i in range(0,1)],
'Y8':[i/2 + 1.4 for i in range(0,1)],
'Y9':[i/2 + 1.6 for i in range(0,1)],
})
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_6 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = marker['X'], y = marker['Y1'],
mode = 'markers', name = 'filled circle',
marker_color = 'black',
marker_size=15, )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y2'],
mode = 'markers', name = 'open square',
marker_color = 'purple',
marker_size=15,
marker_symbol='square-open', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y3'],
mode = 'markers', name = 'filled triangle-up',
marker_color = 'red',
marker_size=15,
marker_symbol='triangle-up', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y4'],
mode = 'markers', name = 'open star',
marker_color = 'black',
marker_size=15,
marker_symbol='star-open', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y5'],
mode = 'markers', name = 'plus',
marker_color = 'blue',
marker_size=15,
marker_symbol='cross', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y6'],
mode = 'markers', name = 'X',
marker_color = 'black',
marker_size=15,
marker_symbol='x', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y7'],
mode = 'markers', name = 'triangle-down',
marker_color = 'gold',
marker_size=15,
marker_symbol='triangle-down', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y8'],
mode = 'markers', name = 'triangle-left',
marker_color = 'black',
marker_size=15,
marker_symbol='triangle-left', )
Figure_6.add_trace(scat)
scat = go.Scatter(x = marker['X'], y = marker['Y9'],
mode = 'markers', name = 'open triangle-right',
marker_color = 'green',
marker_size=15,
marker_symbol='triangle-right-open', )
Figure_6.add_trace(scat)
Figure_6.update_xaxes(title= 'X', mirror = True)
Figure_6.update_yaxes(title= 'Y', mirror = True)
Figure_6.update_layout(title = 'Marker Choice Samples', template = 'simple_white')
Figure_6.show(config = {'toImageButtonOptions': {'format': 'svg'}})
Figure 5: Each marker can be filled or open.
Linewidth and Marker Size¶
These are specified in pixels, so the actual size will vary with the pixel size of the monitor the graph is viewd on. A few examples are shown below.
# CODE BLOCK generated using plot_pandas_GUI(). See https://github.com/JupyterPhysSciLab/jupyter_Pandas_GUI.
from plotly import graph_objects as go
Figure_7 = go.FigureWidget(layout_template="simple_white")
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T2'],
mode = 'lines', name = 'default (2 px)',)
Figure_7.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T3'],
mode = 'lines', name = '6 px',
line_width=6, )
Figure_7.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T4'],
mode = 'markers', name = 'default 6 px',)
Figure_7.add_trace(scat)
scat = go.Scatter(x = LIF2['time(s)'], y = LIF2['T5'],
mode = 'markers', name = '10 px', marker_size=10)
Figure_7.add_trace(scat)
Figure_7.update_xaxes(title= 'Time (s)', mirror = True)
Figure_7.update_yaxes(title= 'Signal', mirror = True)
Figure_7.update_layout(title = 'Examples of various linewidths and marker sizes.', template = 'simple_white')
Figure_7.show(config = {'toImageButtonOptions': {'format': 'svg'}})
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()