Plot data from spice with different program? - Page 1
Forum section: electronics / general

author: eTobey
author_rank: Super Contributor
timestamp: December 08, 2024, 08:26:56 am
content: I wonder if there is a way, to plot the data with another program. Gnuplot would be nice, but the file output is binary, so its not straight forward.Or maybe is there a version that has better plot abilities?Such as:- have fixed scales on the plot window- determine the color of the scale- have a legend of steps, that does not block the mainprogram from beeing used

author: Geoff-AU
author_rank: Frequent Contributor
timestamp: December 09, 2024, 03:04:40 am
content: PyLTSpice is the bridge you're looking for

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 10, 2024, 10:48:35 pm
content: Which Spice?PyLTSpice is for LTSpice and since you thanked without further comments, I'm assuming it may be what you are using.If so, there's a simple way of exporting simulation data as text files from LTSpice, which avoids having to deal with the raw binary format.You need to select the waveform viewer window after having launched a simulation and go to the "File/Export data as text" menu.You can then select the waveforms you want to export.It generates a CSV-like file, but with a 'tab' character as the column separator.Looks like this:Code:timeV(3v3)0.000000000000000e+000.000000e+001.020806909594422e-093.765935e-051.062420785347130e-093.894078e-05...Very easy to deal with in various plotting software.

author: eTobey
author_rank: Super Contributor
timestamp: December 11, 2024, 05:35:25 pm
content: If you do it one time, then it is easy. But do it with a few iterations, then it becomes tedious. Now add some other values after you did a dozen, and you can start all over. It did it this way, and with a little bit of figuring out, and fiddeling with the circuit, it took many hours.Why does this software, that so many people use has such limitations? There is no opensource version of it, is there?

author: TimFox
author_rank: Super Contributor
timestamp: December 11, 2024, 06:29:13 pm
content: With my version of AimSpice, it is straightforward to generate .csv files.I use an expensive professional-grade graphing program that I had used before retirement: "Grapher" from Golden Software.It uses data in an .xlsx file with variables in parallel columns.It makes publication-quality graphs with user control over formats, axes, etc., but is pricey.(They do have a 14-day free trial available.)https://www.goldensoftware.com/products/grapher/

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 12, 2024, 12:24:40 am
content: Quote from: eTobey on December 11, 2024, 05:35:25 pmIf you mean that LTSpice's waveform viewer is limited, yes, definitely. It's quite horrific. At least, in LTSpice 24, they have at least added the possibility of adding plot panes either below or above. You can change the scales by clicking on the axes. But it's not ideal.That said, the only way of getting exactly what you want in terms of graphic output is that, going from an export and using your own tools for plotting.I don't see how tedious it is to use the Export menu though.You can write a Gnuplot file that will take this CSV format and plot with the exact appearance you want.For something free with a GUI, I've also used SciDavis quite often. But I would favor the Gnuplot approach, as once you've written a Gnuplot file, it can be automated.Gnuplot has a rather powerful data import feature (from text) which is not completely trivial to figure out.Here is an example of plotting a Bode plot from the exported text data of an LTSpice AC analysis:(set your plot options/axis as needed before)Code:plot 'xxx.txt' skip 1 using 1:(10**($2/20)) "%lf\t(%lfdB,%lf°)" axes x1y1 title "Gain" with lines linestyle 1, \'' skip 1 using 1:3 "%lf\t(%lfdB,%lf°)" axes x2y2 title "Phase" with lines linestyle 2Where xxx.txt is the filename of the exported file from LTSpice. From that, you should be able to make the changes for plotting transient simulations.

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 12, 2024, 06:36:16 am
content: For LTspice, one can use Python and thePyLTSpicePython module to read the simulation files, save the data in Gnuplot-friendly format (see RawRead), and then execute Gnuplot to plot the saved data file.(Why not do the plotting directly from within the Python script? Because you will be more efficient by keeping individual tools simple and separate, and chain them, than by combining them into a single program. KISS and Unix philosophy are time-tested. After all, youareasking how to do your own plots, having found whatever LTspice provides lacking for this use case.)I don't have LTspice installed, but if someone uploads a .raw file of some simulation, I can write a Python 3 script for converting those to Gnuplot-friendly text format and interactive plotting.I use Gnuplot extensively, and keep a tab open to the user manual (5.4 PDF,6.0 online; seehttp://gnuplot.info/for more). Theplotandsplot(3D) plotting commands are quite powerful, as is thefitcommand. When doing interactive plotting in a script, thepausecommand is particularly useful. If you create a plot for documentation, I recommend doing it interactively first, then switching to SVG output andreplot'ing. SVG is a vector format, so stays sharp at any size, and you can edit them in e.g. Inkscape. (You'll need toEdit>Ungroupobjects before you can modify individual elements.)For Spice simulations, I usengspicethrough KiCad. It uses a text output format compatible with Gnuplot. That output format is also extremely easy to read/modify/write/generate in awk; for example inGNU Awk(usually calledgawk), althoughmawktends to be faster if you use an SBC like RPi. It is also trivial to read into lists in Python; however, I do recommend outputting the data into a text file and using Gnuplot the external program, rather than writing Python programs that redraw the graphs (even using libgnuplot).In non-Windows operating systems there are tools likeinotifywaitandfswatchthat can monitor when any process closes a watched file (or any file in a watched directory) having it open for writing, i.e.CLOSE_WRITEevent forinotifywait. This makes it very easy to write one-line shell (command-line) commands that run a program, for example Gnuplot, whenever a process closes a file that it opened for write access. It is much more reliable than checking file timestamps, because modification timestamps are updated even while the process has the file still open, so there is no guarantee the modifications are complete immediately after the modification timestamp changes. (Whilefswatchdoes support Windows, it does not support this on Windows, and only tries to emulate it by monitoring the file timestamps; the close-write event should work in Linux, Android, FreeBSD, OpenBSD, and macOS.)