Style plots with plot_datasets#

The plot_datasets function has a parameter layout_kwargs - any extra named arguments will be passed into figure.update_layout() (a plotly function for changing graphs after they are created), this is how plots should be styled.

For a list of all available layout options see layout plotly reference. Here are some examples:

Changing title and axis titles#

import eafpy as eaf
sets = eaf.read_datasets("input1.dat")
subset = eaf.subset(sets, range = [6,10])
plot = eaf.plot_datasets(subset, type="points, lines",title="Tastiness of fruit vs ease of eating",
                         xaxis_title="Ease of eating score", yaxis_title="Tastiness of fruit score")
plot.show()

Changing the template#

Plotly allows for 11 basic templates that can be selected to change the colour scheme and basic visual appearance. These include: ‘ggplot2’, ‘seaborn’, ‘simple_white’, ‘plotly’,’plotly_white’, ‘plotly_dark’, ‘presentation’,’xgridoff’,’ygridoff’, ‘gridon’, ‘none’

The default look is “plotly”. Custom templates can be created and used template plotly reference

Example of changing template to “plotly_dark”

import eafpy as eaf
sets = eaf.read_datasets("input1.dat")
subset = eaf.subset(sets, range = [6,10])
plot = eaf.plot_datasets(subset, type="lines", template="plotly_dark")
plot.show()

Changing graph colour scheme#

Use the colorway argument to change the color sequence of the traces. This can be:

  • a list of colours in string form ['red', 'green', 'blue']

  • a list of rgb values in string form eg. ['rgb(123,23,12)', 'rgb(13,12,32)']

  • One of the pre-set sequences defined in px.colors.qualitative (see below)

import plotly.express as px
print("available presets: " + str(dir(px.colors.qualitative)))
print("Example of a preset: " + str(px.colors.qualitative.Prism))
available presets: ['Alphabet', 'Alphabet_r', 'Antique', 'Antique_r', 'Bold', 'Bold_r', 'D3', 'D3_r', 'Dark2', 'Dark24', 'Dark24_r', 'Dark2_r', 'G10', 'G10_r', 'Light24', 'Light24_r', 'Pastel', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'Pastel_r', 'Plotly', 'Plotly_r', 'Prism', 'Prism_r', 'Safe', 'Safe_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'T10', 'T10_r', 'Vivid', 'Vivid_r', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_swatches', 'swatches']
Example of a preset: ['rgb(95, 70, 144)', 'rgb(29, 105, 150)', 'rgb(56, 166, 165)', 'rgb(15, 133, 84)', 'rgb(115, 175, 72)', 'rgb(237, 173, 8)', 'rgb(225, 124, 5)', 'rgb(204, 80, 62)', 'rgb(148, 52, 110)', 'rgb(111, 64, 112)', 'rgb(102, 102, 102)']

The colorway argument takes priority over the template colorway (A template includes its own colorway)

import eafpy as eaf
import plotly.express as px
sets = eaf.read_datasets("input1.dat")
subset = eaf.subset(sets, range = [6,10])
plot = eaf.plot_datasets(subset, type="lines", template="plotly_dark", colorway=px.colors.qualitative.Vivid)
plot.show()

Creating colour gradients using the eaf.colour module#

Use the eaf.colour.discrete_colour_gradient to create objects for the colorway argument. This function lerps between two colours in a discrete number of steps. It accepts the following type of colour arguments:

  • Standard CSS4 color name strings - Eg. “blue”

  • Strings of rgba values, 0-1 or 0-255 - Eg. ‘rgba(123,54,22, 0.8)’ -> this is a brown colour with 80% opacity

  • 8 digit hexedecimal numbers representing RGBA values Eg. #abcdefFF -> #abcdef is a light blue colour with alpha = (FF) = 100% opacity

import eafpy as eaf
dat = eaf.read_datasets("input1.dat")
eafs = eaf.get_eaf(dat, percentiles = [10, 20, 50, 75 ,90, 100])
gradient = eaf.colour.discrete_colour_gradient("darkorchid","crimson", num_steps=6)
fig = eaf.plot_eaf(eafs, colorway = gradient)
fig.show()

Example using 'rgba(r,g,b,a)' style arguments. Both the opacity and colour can be interpolated to create the gradient

import eafpy as eaf
dat = eaf.read_datasets("input1.dat")
eafs = eaf.get_eaf(dat, percentiles = [25, 50, 75, 100])
gradient = eaf.colour.discrete_colour_gradient("rgba(0,139,139,0.4)","rgba(255,20,147,1)", num_steps=4)
fig = eaf.plot_eaf(eafs, colorway = gradient)
fig.show()