Miscellaneous

Setup

Import packages:


import fivecentplots as fcp
import pandas as pd
from pathlib import Path

Read some dummy data for examples:


df = pd.read_csv(Path(fcp.__file__).parent / 'test_data/fake_data.csv')
df.head()

Substrate Target Wavelength Boost Level Temperature [C] Die Voltage I Set I [A]
0 Si 450 0.2 25 (1,1) 0.0 0.0 0.0
1 Si 450 0.2 25 (1,1) 0.1 0.0 0.0
2 Si 450 0.2 25 (1,1) 0.2 0.0 0.0
3 Si 450 0.2 25 (1,1) 0.3 0.0 0.0
4 Si 450 0.2 25 (1,1) 0.4 0.0 0.0

Optionally set the design theme (skipping here and using default):


#fcp.set_theme('gray')
#fcp.set_theme('white')

Text boxes

One or more text boxes can be added to any plot via the text Element class.

Single text box

First we consider a single, non-styled text box:


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows best response', text_position=[0, 380])
_images/misc_12_0.png

Single text box with styling

We can enhance the look of the text box by accessing color and font properties in the text object using keyword arguments or by definition in a custom theme file. For example, to set the text box fill color, use text_fill_color. The following attributes are defined by default for a text box:

  • edge_color: none

  • fill_color: none

  • font: sans-serif

  • font_size: 14

  • font_style: normal

  • font_weight: normal


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows\nbest response', text_position=[10, 340], text_font_size=20,
         text_edge_color='#FF0000', text_font_color='#00FF00', text_fill_color='#ffffff')
_images/misc_15_0.png

Multiple text boxes

We can also add multiple text boxes. Because each styling attribute is a RepeatedList, we do not have to explicitly define all attributes for each text box. The provided list of attributes or defaults is cycled through for each text box. Notice below that we define a custom position and font size for each text string, but only one fill_color and only two font_color values. Because these attributes are RepeatedList objects, all elements share the same fill_color and the first and third text string share the same font_color.


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text=['Die (-1,2) shows best response', '(c) 2019', 'Boom!'],
         text_position=[[10, 379], [10, 10], [320, 15]], text_font_color=['#000000', '#FF00FF'],
         text_font_size=[14, 8, 18], text_fill_color='#FFFFFF')
_images/misc_18_0.png

Position

Coordinate systems

Text box locations can be specified relative to different elements of a given figure:

  • axis: (0,0) is at the lower left corner of the plot window [default]

  • figure: (0,0) is at the lower left corner of the entire figure window

  • data: position is relative to the actual x,y data coordinates

This value is toggled using the text_coordinate keyword. In the examples below, notice how the text_position must change with each coordinate system in order to keep the text box in the same general location.

By “axis” [default]


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows best response', text_position=[0, 380])
_images/misc_23_0.png

By “figure”


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows best response', text_position=[110, 440], text_coordinate='figure')
_images/misc_25_0.png

By “data”


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows best response', text_position=[0.903, 1.2], text_coordinate='data')
_images/misc_27_0.png

Units

By default, “axis” and “figure” referenced position values are units of pixels. We can cast these into relative units between 0 and 1 (0 and 100%) of scale using the keyword text_units.


fcp.plot(df, x='Voltage', y='I [A]', ax_scale='loglog', legend='Die', xmin=0.9,
         filter='Substrate=="Si" & Target Wavelength==450 & Boost Level==0.2 & Temperature [C]==25',
         text='Die (-1,2) shows best response', text_position=[0, 0.95], text_units='relative')
_images/misc_30_0.png