Author Topic: Plot data from spice with different program?  (Read 706 times)

0 Members and 1 Guest are viewing this topic.

Offline eTobeyTopic starter

  • Super Contributor
  • ***
  • Posts: 1166
  • Country: de
  • Virtual Features for the SDS800XHD -> My website
    • Virtual feature script
Plot data from spice with different program?
« on: December 08, 2024, 08:26:56 am »
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
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
My current top list of issues on the SDS800X HD:
https://www.eevblog.com/forum/testgear/sds800x-hd-bug-reports-firmware/msg5766323/#msg5766323
 

Offline Geoff-AU

  • Regular Contributor
  • *
  • Posts: 241
  • Country: au
Re: Plot data from spice with different program?
« Reply #1 on: December 09, 2024, 03:04:40 am »
PyLTSpice is the bridge you're looking for
 
The following users thanked this post: eTobey

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15759
  • Country: fr
Re: Plot data from spice with different program?
« Reply #2 on: December 10, 2024, 10:48:35 pm »
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: [Select]
time V(3v3)
0.000000000000000e+00 0.000000e+00
1.020806909594422e-09 3.765935e-05
1.062420785347130e-09 3.894078e-05
...

Very easy to deal with in various plotting software.
 
The following users thanked this post: Someone

Offline eTobeyTopic starter

  • Super Contributor
  • ***
  • Posts: 1166
  • Country: de
  • Virtual Features for the SDS800XHD -> My website
    • Virtual feature script
Re: Plot data from spice with different program?
« Reply #3 on: December 11, 2024, 05:35:25 pm »
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?
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
My current top list of issues on the SDS800X HD:
https://www.eevblog.com/forum/testgear/sds800x-hd-bug-reports-firmware/msg5766323/#msg5766323
 

Offline TimFox

  • Super Contributor
  • ***
  • Posts: 8991
  • Country: us
  • Retired, now restoring antique test equipment
Re: Plot data from spice with different program?
« Reply #4 on: December 11, 2024, 06:29:13 pm »
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/
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15759
  • Country: fr
Re: Plot data from spice with different program?
« Reply #5 on: December 12, 2024, 12:24:40 am »
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?

If 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: [Select]
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 2

Where 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.

 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7159
  • Country: fi
    • My home page and email address
Re: Plot data from spice with different program?
« Reply #6 on: December 12, 2024, 06:36:16 am »
For LTspice, one can use Python and the PyLTSpice Python 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, you are asking 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; see http://gnuplot.info/ for more).  The plot and splot (3D) plotting commands are quite powerful, as is the fit command.  When doing interactive plotting in a script, the pause command is particularly useful.  If you create a plot for documentation, I recommend doing it interactively first, then switching to SVG output and replot'ing.  SVG is a vector format, so stays sharp at any size, and you can edit them in e.g. Inkscape.  (You'll need to Edit > Ungroup objects before you can modify individual elements.)

For Spice simulations, I use ngspice through 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 in GNU Awk (usually called gawk), although mawk tends 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 like inotifywait and fswatch that can monitor when any process closes a watched file (or any file in a watched directory) having it open for writing, i.e. CLOSE_WRITE event for inotifywait.  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.  (While fswatch does 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.)
« Last Edit: December 12, 2024, 06:41:48 am by Nominal Animal »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf