PyICe.LTC_plot¶
Marcom Compliant Plot Generator
This program can be used to generate plots for general lab use or to generate Marcom specific plots that can be imported directly into the datasheet in SVG format.
- The objects that can be created with this program are:
- plot
- Page
- Multipage_pdf
The basic model is simple. You create one or more plots and add things to them like traces, histograms, legends, arrows, notes, etc. Once your plots are populated you create one or more pages and determine how you want the plots to arrange on each page. For instance you can create an 8.5x11 page and add 9 plots to it in a standard 3x3 grid. You can make one big page if you want. It doesn’t have to be a standard size if you don’t care what the printer does with it and it won’t affect your SVG files to Marcom. If you want to have multiple pages of plots you can create a Mulipage_pdf and add one or more pages to it.
If you want larger plots with just one plot per page as in plot_tools.py you can create a page per plot, add a plot to each page and add all of the pages to a Multipage_pdf.
So to start, you’ll need to create a python work file and import this program: e.g.
----------- LTCXXXX_plots.py --------------
|import sys |
|sys.path.append("../../../PyICe") |
|import LTC_plot |
| . |
| . |
| . |
-------------------------------------------
Next you want to create your plots. A generally preferable work flow would be to create all of your plots without regard to reference on a Page or Multipage_pdf.
G0 = LTC_plot.plot(
plot_title = "EN/FBIN Thresholds",
plot_name = "8709 G0",
xaxis_label = "TEMPERATURE (" + DEGC + ")",
yaxis_label = "FBIN CHIP ENABLE (V)",
xlims = (-50, 125),
ylims = (1.2, 1.4),
xminor = 0,
xdivs = 7,
yminor = 0,
ydivs = 10,
logx = False,
logy = False)
A plot is nothing more than a record of the plot you want to create. It doesn’t support any outputting methods itself. A plot must eventually be added to a Page to be useful. Only a Page can be generated as an SVG file, even if there’s only one plot on the page.
The arguments of a plot instance are shown below. All plot arguments are required.
plot_title : “string” plot_name : “string” xaxis_label : “string” yaxis_label : “string”
Accepts control characters such as n to start a second line. These text fields also respond to Tex formatting for subscripting There are a few unicode characters available in LTC_plot to help with greek characters and degree signs, etc. Be aware that the Marcom minus sign is not the same as the one you type. You may wan to use LTC_plot.minus.
xlims : (xmin, xmax) ylims : (ymin, ymax)
These two fields also accept python None or string “auto” for automatic scaling. Autoscaling is useful to view the data for the first time and then the final values can be entered later once the data is understood.
- xminor : 0
- This is the number of minor X divisions per major X division.
- xdivs : 7
- This is the number of major X divisions.
- yminor : 0
- This is the number of minor Y divisions per major XY division.
- ydivs : 10
- This is the number of major Y divisions.
- logx : False
- Sets the X axis to a log scale with locators at [1,2,3,4,5,6,7,8,9].
- logy : False
- Sets the Y axis to a log scale with locators at [1,2,3,4,5,6,7,8,9].
- Once you have a plot you can add things to it such as:
- add_trace()
- add_histogram()
- add_note()
- add_legend()
- add_arrow()
- make_second_y_axis()
The most common element is a trace. You can add as many traces as you like. The same is true of histograms. You can also put traces and histograms on the same plot (for instance to show the Gaussian normal curve).
When you add a trace you have the option to specify line style and marker. Linear datasheets often use dotted or dot dash lines for improved black and white readability but rarely if even use markers so use them judiciously.
- Valid linestyles are:
- ‘-‘
- ‘–’
- ‘-.’
- ‘:’
- and valid markers are:
- ‘:’
- ‘.’
- ‘,’
- ‘o’
- ‘v’
- ‘^’
- ‘<’
- ‘>’
- ‘1’
- ‘2’
- ‘3’
- ‘4’
- ‘8’
- ‘s’
- ‘p’
- ‘*’
- ‘h’
- ‘H’
- ‘+’
- ‘x’
- ‘D’
- ‘d’
- ‘|’
- ‘_’
- TICKLEFT
- TICKRIGHT
- TICKUP
- TICKDOWN
- CARETLEFT
- CARETRIGHT
- CARETUP
- CARETDOWN
Please see matplot lib docs online for more details.
- Trace colors currently supported are:
- LT_RED_1
- LT_BLUE_1
- LT_GREEN_1
- LT_COPPER_1
- LT_BLACK
- LT_COPPER_2
- LT_RED_2
- LT_BLUE_2
- LT_GREEN_2
- LT_YELLOW_2
- LT_BLUE_2_40PCT
- LT_RED_1_40PCT
You can make your own colors by entering a list of RGB colors (r,g,b), all of which should be between 0 and 1 rather than 0 to 255. This is strongly discouraged however, as it will not be in compliance with LTC standards and should not make its way to Marcom.
- add_legend takes arguments:
- axis
- location
- justification
- use_axes_scale
- axis
- The axis from which the legend items have been added.
- location
- Coordinates in an xy list (x, y) of where to place the legend. These are relative, see use_axes_scale.
- justification
- Justification of the test of the legend. Accepts:
- “best”
- “upper right”
- “upper left”
- “lower left”
- “lower right”
- “right”
- “center left”
- “center right”
- “lower center”
- “upper center”
- “center”
- use_axes_scale:
- True means place the legend by the scale of the data values whereas False means use values from 0 to 1 representing data independent percentage of the graph size.
Notes, on the other hand, need to have coordinates given. Both support the use_axes_scale argument which defaults to True referencing the item to the data values rather than as a percentage (0..1) of the graph limits.
Data can come from a number of sources such as a CSV file or a .sqlite database and should be a zipped list of (x,y) values for a trace and just a list for a histogram. Consult the examples file for details.
You can also add as many notes as you like. The position of the notes can be set by either referring them to the axes_scale, a scale relative to your data or a percentage scale (0..1) of the axes extents. The default is to use the scale of your data. This should be easier to help you locate the notes, etc as the graticules will more precisely help you picture where the item will be.
You can only add one legend. For each trace on a given axis, it will place a label preceded by a line stub in the same color and width of the trace. Generally the legend will placed along side the axis to which it belongs but you can specify where it goes.
An arrow is based on the matplotlib annotate() object and consists of a text box with an arrow emanating from it. You control where the lower left corner of the text goes as well as the arrow tip.
If you add a second y axis you have to, once again, specify a few required items in a similar manner to when you created the plot: 1) yaxis_label 2) ylims 3) yminor 4) ydivs 5) logy
As you add traces and histograms you’ll need to specify to which axis they belong (1 or 2).
Once you have created all of your plots you will need to add them to a page:
Page1 = Page(rows_x_cols = (3, 3), page_size = (8.5, 11))
Defaults for rows_x_cols = (1, 1) and for page_size is None. If you omit the page_size or specify None, the page will shrink to fit the plots you add to it. If, on the other hand, you specify a page size and the plots you add to it don’t quite fit, the plots will overlap a bit. That won’t matter for datasheet importation as you’ll see later. Alternately, if your plots are swimming on your page, they’ll be spread out to roughly fill the Page.
- Pages support the following methods:
- add_plot()
- create_pdf()
- create_svg()
- kit_datasheet()
add_plot() has options to change the plot size on the page such as plot_sizex and plot_sizey. These values are extremely specific to datasheets and should not be changed if the plots are to be sent to Marcom. It’s best to enter the plot instance and position and leave the rest alone.
Page1.add_plot(G01, position = 1)
Page1.add_plot(G02, position = 2)
Page1.add_plot(G03, position = 3)
As you add plots to the page with a given position, the plots appear on the page top to bottom, left to right.
So a Page that was specified as 3x3 would add up to 9 plots in the following order:
---------------------------
| |
| [1] [2] [3] |
| |
| |
| [4] [5] [6] |
| |
| |
| [7] [8] [9] |
| |
---------------------------
Or a 2x2 Page would be positioned as:
-------------------
| |
| [1] [2] |
| |
| |
| [3] [4] |
| |
-------------------
- Pages support the following methods:
- create_pdf(“LTCXXXX_Page1”)
- create_svg(“LTCXXXX_Page1”)
- kit_datasheet(“LTCXXXX_Page1”)
Each of these takes just a file_basename. The file extension is added to match the output.
All output data you request is place in a newly created folder under your work area called “/plots”.
- kit_datasheet() performs the following sequence for you:
- Creates a zip file.
- Creates a disposable page.
- Adds one plot that is found on your Page.
- Creates an SVG file of the disposable page and adds it to the zip file.
- Repeats for each plot on your Page. The disposable Page evaporates.
- Creates a PDF of your entire page for reference and dumps it in the zip file.
If you end up needing more than one page of plots you can add your pages to a Multipage_pdf:
LTCXXXX_typcurves = Multipage_pdf("LTCXXXX_typcurves")
LTCXXXX_typcurves.add_page(Page1)
LTCXXXX_typcurves.add_page(Page2)
LTCXXXX_typcurves.kit_datasheet()
- Multipage_pdfs support the methods:
- kit_datasheet(“LTCXXXX_Page1”)
- create_pdf(“LTCXXXX_Page1”)
To really get going and find more example see:
PyICeExamplesLTC_plot_exampleLTC_plot_example.py
- * TIP *
- If you get a warning about missing Linear fonts and you have them installed, try deleting: “C:\Users\%username%\.matplotlib\fontList.cache and tex.cache”
Functions
CMYK_to_fracRGB (CMYK) |
|
RGB_to_fracRGB (RGB) |
|
RGB_to_webRGB (RGB) |
|
data_from_file (filename) |
|
fracRGB_to_CMYK (RGB) |
|
fracRGB_to_RGB (fracRGB) |
|
fracRGB_to_webRGB (fracRGB) |
|
list_markers () |
Valid linestyles are [‘-‘ ‘–’ ‘-.’ ‘:’ ‘None’ ‘ ‘ ‘’] |
smooth (data[, window]) |
|
smooth_y_vector (data[, window]) |
|
webRGB_to_RGB (webRGB) |
|
webRGB_to_fracRGB (webRGB) |
Classes
Multipage_pdf () |
Add one or more Pages to a Multipage_pdf to keep your page sizes manageable (such as 8.5x11). |
Page ([rows_x_cols, page_size, plot_count]) |
|
PyICe_data_base (table_name[, file_name]) |
|
color_gen ([rollover]) |
Color yielding generator. |
plot (plot_title, plot_name, xaxis_label, ...) |
|
scope_plot (plot_title, plot_name, ...) |
-
class
PyICe.LTC_plot.
Multipage_pdf
[source]¶ Add one or more Pages to a Multipage_pdf to keep your page sizes manageable (such as 8.5x11). Multipage_pdf also support kit_datasheet().