# Add a trace from a directive in LTSpice

I have a circuit in LTSpice in which I want to measure some differential voltages, currently I'm manually adding the traces using the "Add Trace" menu in the plot view and writing its expressions.

I would like to know if there's a way to do this using a directive so that every time I run the simulations those traces are automatically added.

• A good place to ask would be at the LTspice user group. Oct 24 '15 at 15:25
• Well, it's a bit unclear what you're asking. The plot settings are saved in a separate ".raw" file. This [alas] isn't automatically reopened when you open an ".asc" file, but you can manually open it. Furthermore after you run a simulation and make a plot, the plot doesn't go away if you change some value in the circuit but gets automatically updated when you rerun the simulation. If you alter the circuit in terms of nodes/components however, those plots affected by node/component deletions do go away.
– Fizz
Oct 24 '15 at 15:41
• Actually, the plot data is saved in the ".raw" file (which can also be exported to other formats like csv). The plot settings are saved to a ".plt" file, which you can also save/open. This file is just text, but its format has little in common with SPICE; looks more like yaml. I doubt you can achieve the full functionality of this from SPICE directives.
– Fizz
Oct 24 '15 at 16:01
• Here's a non-trivial example. It has two (split) plot panes and power displayed on one pane (which I suppose you know you can get with Alt+click). The plots look like in this answer.
– Fizz
Oct 24 '15 at 16:06
• Gonna add that other SPICEs that are less interactive by design, e.g. hspice definitely have something like this, .plot in that case. I guess LTspice's developer thought it unnecessary. The intersting thing is that you can add a directive like .plot I(R1), to a LTspice shematic; it causes no error, but doesn't do anything either.
– Fizz
Nov 29 '15 at 23:52

One method would be to plot the quantity you need, be it a single trace or a mathematical combination of more (maybe also plot whatever other traces you need), then click on the waveform viewer to activate it (if you haven't already) and then click on the Save icon in the toolbar (or in the File menu). This will save the .plt file with the plot settings @Fizz was talking about. This way, whenever you first open up the schematic and run it, or click on the Add trace, the plot window will open up with the saved traces already selected and plotted. The downside is that, once you plot/delete traces, the waveforms will change and, if you need to replot some saved ones, you'll have to manually add them. The minor upside to this is that, if you don't care about the recently added traces, you can close the waveform viewer and click on Add trace, which will, again, open up the previously saved traces and plot them, at the cost of losing the recently plotted ones.
A similar method is to modify the default, global .plt file, but it might not be such a great idea. Still, if you want to, activate the waveform window and then go to the menu in Plot Settings > Edit plot defs file.
Another method is to use behavioural sources, but these, as versatile as they are, come at a cost in that they get slower as the dynamic range gets higher (both frequency-, or time-wise, and value-wise). But, if you have more involved quantities to plot (some bogus example: (V(A)*V(C)+V(B)*V(D))/(I(R1)-I(R2))*sqrt(3)/2), and this doesn't go above hundreds or thousands, in value, or it doesn't have very high frequency components compared to the simulation window, it's safe to use. Then, plotting the formula is as easy as plotting the voltage of the behavioural source.