Menu

#83 Legend on graphs

v1.0 (example)
open
nobody
None
5
2025-10-26
2025-10-23
No

Good evening,

I made a current-voltage graph at different temperatures for my circuit but it doesn't show me any legend or a label about the curves' temperatures (only have different colors). As I searched the ngspice44 manual, it doesn't have a guide on how to create a legend, only how to delete it. Is there a way so I can create a legend or somehow change the names of the different current-voltage curves (the r2#branch on my example) so I can distinguish each temperature?

Here is the code I have until now
" name=NGSPICE_code only_toplevel=false value=
"
.lib cornerMOSlv.lib mos_tt
.control
.probe I(r2)
foreach operating_temprature 27 127 227
set temp = $operating_temprature
DC VDD 0 1.2 0.1
run
end
plot all.I(r2)
+ title 'Current vs Voltage'
+ xlabel 'Supply Voltage (V)'
+ ylabel 'Circuit Current (uA)'
write Reference_Current_design.raw
.endc
.save all
.END
"

", and the photo is my current results from the graph.

Thank you for your time.

1 Attachments

Discussion

  • Giles Atkinson

    Giles Atkinson - 2025-10-23

    Without the library, your test case can not be reproduced, but I think you will get a better result with "plot dc1.I(r2) plot dc2.I(r2) plot dc3.I(r2) " in place of "plot all.I(r2)". Or you could do some more scripting, and copy those vectors to get more meaningful names.

    Interesting to me, as I did not know that use of "all" even existed! Where did you find it?

     
  • Holger Vogt

    Holger Vogt - 2025-10-23

    Scripting with the ngspice control language seems somewhat special. But it is powerful if you know what to do.

    See this:

    * support request 83
    * create legends
    
    *.lib D:\Spice_general\IHP-Open-PDK\ihp-sg13g2\libs.tech\ngspice\models\cornerMOSlv.lib mos_tt
    
    R2 1 0 1 TC1=1e-3 TC2=1e-5
    VDD 1 0 1
    
    .save all
    .probe I(r2)
    
    .control
    set myplot = ( ) ; create a variable later used in the plot command
    foreach operating_temprature 27 127 227
    set temp = $operating_temprature
    DC VDD 0 1.2 0.1
    let curr{$operating_temprature}=I(r2)
    *add the current from this plot to the myplot variable
    set myplot = ( $myplot {$curplot}.curr{$operating_temprature} ) 
    end
    
    set nounits
    
    * the original plot, however not using line concatenation (avoid all becoming lower case)
    *plot all.I(r2)  title 'Current vs Voltage' xlabel 'Supply Voltage (V)' ylabel 'Circuit Current (uA)'
    
    * suggested by Giles, you have to know the plot names
    *plot dc1.I(r2) dc2.I(r2) dc3.I(r2)  title 'Current vs Voltage' xlabel 'Supply Voltage (V)' ylabel 'Circuit Current (uA)'
    
    * having added the temperature to the label, still you have to know the plot names
    *plot dc1.curr27 dc2.curr127 dc3.curr227  title 'Current vs Voltage' xlabel 'Supply Voltage (V)' ylabel 'Circuit Current (uA)'
    
    * all included automatically
    echo We are going to plot $myplot
    plot $myplot  title 'Current vs Voltage' xlabel 'Supply Voltage (V)' ylabel 'Circuit Current (uA)'
    
    *+ title 'Current vs Voltage'
    *+ xlabel 'Supply Voltage (V)'
    *+ ylabel 'Circuit Current (uA)'
    write Reference_Current_design.raw $myplot
    .endc
    
    .END
    
     

    Last edit: Holger Vogt 2025-10-24
  • Kostas Karalis

    Kostas Karalis - 2025-10-26

    Good evening,

    First of all, I would like to thank both of you for your prompt and helpful responses (and especially Mr. Vogt for the code, which was very helpful and works perfectly for my problem).
    Regarding your question, Mr. Atkinson, about the .all method, I found it in other code examples I came across online, as well as in ngspice-44 manual in section 18.5.2.1.
    I hope I won’t have to bother you again, although it’s quite possible since I’m doing my thesis using ngspice, and it’s the first time I’m working with it.

    Thank you both very much once again for your time.

     

Log in to post a comment.