I’ve been engaged on an article about vacuum tube triodes. Sure, they’re nonetheless getting used within the manufacture of high-end audio tools and in musical instrument amplifiers. A triode has three electrodes: a plate (in American parlance, “anode” within the UK), a management grid, and a cathode.
Determine 1 comprises a typical graph of plate currents verses plate voltages for various grid voltages, with grid voltages labeled on every curve as 0, -0.5, -1. 0…-5.0. All voltages are with respect to the cathode. Fairly clear, proper?
Determine 1 A typical graph of triode traits from a producer’s datasheet.
A part of the article includes measuring triode traits and establishing graphs in Excel which show the measured knowledge. Determine 2 exhibits the primary try to current this graphically.
Determine 2 A easy show of the acquired knowledge, the colours proven are defaults chosen by Excel.
The information for the left-most curve was entered first; the one instantly to the suitable subsequent, and so forth. Excel assigns curve colours within the order proven by default. There doesn’t appear to be any order to the development of colours which may assist in scanning by the LEGEND desk on the suitable to discover a curve’s grid-voltage title.
And a few of the colours are so comparable that it may be difficult to search out the suitable affiliation. There’s additionally no straightforward method to label the LEGEND desk to point the kind of data it comprises aside from including a textual content field to the chart. However in case you reposition the chart, the textual content field have to be moved individually.
There have to be a greater method to convey this data to the reader. Suppose the colours could possibly be modified to a extra recognizable development, such because the seen spectrum-related order of the colour bands on a resistor which signifies its resistance. Moreover, what if this reordering could possibly be automated with a keyboard click on for any chart? We’re speaking Excel macros, proper? We may manually make the change for one graph and report the steps as a macro. However we’d need to know what number of curves a specific graph had to make use of such. Hmmm.
Okay, let’s as an alternative create a macro utilizing the subroutine “sub” function in Excel’s built-in Visible Fundamental for Purposes (VBA) code. The code ought to be simply capable of deal with a chart with any variety of curves. Now, I’ve labored with VBA, however I’m no professional. So, after I come throughout a function I would like however I’m not accustomed to, I’ve to do a web based search, discover a reference that I can perceive, and apply and check it. Rinse and repeat. That is tedious. Is there a work-around for a time-crunched, lazy man like me? Seems the reply is sure: AI.
I requested considered one of these well-known beasts how I would routinely re-order the colours assigned to Excel chart curves. The code it returned in reply labored the primary time and got here with feedback! I’ve made a number of adjustments and added some feedback of my very own to provide the code listed in Appendix 1. Clicking to pick out the chart proven in Determine 2 and working this code produces the outcomes seen in Determine 3.
Determine 3 The curve colours progress in the identical order because the resistance color-code bands on resistors, and backgrounds had been coloured for higher visibility of the yellow and white curves.
Along with reordering the colours, the code has thickened the curves and added a background coloration of sunshine gray for higher visibility. All of the code is commented, and the background and curve thicknesses may be simply modified. You’ll discover that there are eleven curves however solely ten colours, so the -5.0-volt curve is identical coloration because the 0.0-volt curve; the colours routinely repeat.
However one of many options of the code is its skill to alter what’s known as the “dashstyle” of the curves every time the colours repeat. I imagine that the code is satisfactorily commented to permit a person to find and modify or remove this conduct if desired.
Labeling the curves
I used to be pleased with this till I regarded again on the chart in Determine 1. Why discuss with a legend on the aspect of the graph if I may put the grid-voltage curve names proper subsequent to the curves themselves? I went again to the AI engine to ask for assist. This time, I bought code that didn’t work the primary time. However that didn’t cease me; after I described the issues I used to be seeing particularly, I bought debugging assist! Clicking to pick out the chart rendered in Determine 2, the Appendix 2 code produced the graph seen in Determine 4.
Determine 4 Every curve’s grid-voltage title is positioned subsequent to the tip of the curve.
Perhaps you’d like to mix results by working the Appendix 1 code on Determine 4’s chart to provide that seen in Determine 5.
Determine 5 The Appendix 1 and Appendix 2 codes are run sequentially: first the code which appends the curve names close to the ends of the curves, after which the code which reorders the curve colours.
There’s now not any want for the legend field, so I manually deleted it after working the codes.
I discovered the 2 VBA applications offered within the first two Appendices to offer a easy, fast, and computerized means to reinforce the readability of fundamental graphs in Excel. I’m retaining them in my Excel toolbox. For these unfamiliar with the right way to use VBA, Appendix 3 ought to show useful.
Christopher Paul has labored in numerous engineering positions within the communications business for over 40 years.
Associated Content material
- Inform us your Story
- What’s the largest mistake you could have made as an engineer?
- Visualizing Information with Arduino
- PUT a reset as an alternative
APPENDIX 1
Code to specify the colours assigned to curves on a chart. Choose a chart and run the macro related to this code.
Sub ApplySpectrumColors()
Dim cht As Chart, sequence As sequence, i As Integer
Dim colors_ As Variant, line_type As Variant, the_weight As Variant
' Outline the spectrum colours as RGB values
' (see https://www.teoalida.com/wordpress/wp-content/uploads/Excel-colors-with-RGB-values-by-Teoalida.png)
colors_ = Array(RGB(32, 0, 0), RGB(160, 140, 0), RGB(255, 128, 128), RGB(255, 192, 128), RGB(255, 255, 0), RGB(0, 192, 0), _
RGB(96, 255, 255), RGB(176, 96, 255), RGB(211, 211, 211), RGB(255, 255, 255))
' Outline the road varieties. See https://study.microsoft.com/en-us/workplace/vba/api/workplace.msolinedashstyle
line_type = Array(msoLineSolid, msoLineLongDash, msoLineDashDot, msoLineSquareDot)
' Outline line_type weights (thicknesses)
the_weight = Array(3, 3, 4, 4)
' Reference the lively chart
On Error Resume Subsequent
Set cht = ActiveChart
On Error GoTo 0
If cht Is Nothing Then
MsgBox "Please choose a chart earlier than working this script.", vbExclamation
Exit Sub
Finish If
' Loop by every sequence and assign spectrum colours,line kinds and weights
i = 0
For Every sequence In cht.SeriesCollection
sequence.Format.Line.ForeColor.RGB = colors_(i Mod (UBound(colors_) + 1))
sequence.Format.Line.DashStyle = line_type(Int(i / (UBound(colors_) + 1)) Mod (UBound(line_type) + 1))
sequence.Format.Line.Weight = the_weight(Int(i / (UBound(colors_) + 1)) Mod (UBound(the_weight) + 1))
i = i + 1
Subsequent sequence
' Change Plot Space Background Coloration
cht.PlotArea.Format.Fill.ForeColor.RGB = RGB(236, 236, 236)
' Change Legend Background Coloration
cht.Legend.Format.Fill.ForeColor.RGB = RGB(236, 236, 236)
MsgBox "Spectrum colours utilized efficiently!", vbInformation
Finish Sub
APPENDIX 2
Code to put the names of every curve subsequent to that curve on a chart. Choose a chart and run the macro related to this code.
Sub LabelCurvesWithStyle()
Dim cht As Chart, srs As sequence, pt As Level, i As Integer, seriesCount As Integer
Dim validSeriesCount As Integer, lastValue As Variant
On Error Resume Subsequent
Set cht = ActiveChart ' Get the lively chart
On Error GoTo 0
If cht Is Nothing Then ' If no chart is chosen
MsgBox "No chart is chosen. Click on on a chart and take a look at once more.", vbExclamation, "Error"
Exit Sub
Finish If
seriesCount = cht.SeriesCollection.Depend 'variety of sequence within the chart
validSeriesCount = 0
' Loop by every sequence within the chart
For Every srs In cht.SeriesCollection
If srs.Factors.Depend > 0 Then
i = srs.Factors.Depend ' Final level within the sequence
lastValue = srs.Values(i) ' Get the final Y worth
' Examine if final worth is numeric earlier than labeling
If IsNumeric(lastValue) And Not IsEmpty(lastValue) Then
Set pt = srs.Factors(i)
' Add a label
pt.HasDataLabel = True
pt.DataLabel.Textual content = srs.Title
pt.DataLabel.Place = xlLabelPositionRight ' for otherlabel positions, see
' https://study.microsoft.com/en-us/workplace/vba/api/Excel.XlDataLabelPosition
With pt.DataLabel.Font ' Set font styling
.Title = "Arial" ' Font kind
.Measurement = 10 ' Font measurement
.Daring = True ' Make textual content daring
.Coloration = RGB(255, 0, 0) ' Font coloration (Purple)
'.Italic = True ' Uncomment for italic textual content
Finish With
validSeriesCount = validSeriesCount + 1
Else
MsgBox ("Collection labeled " & srs.Title & " has non-numeric knowledge.")
Finish If
Finish If
Subsequent srs
If validSeriesCount < seriesCount Or validSeriesCount = 0 Then
MsgBox "Non-numeric knowledge present in a minimum of one sequence. No labels utilized."
Finish If
Finish Sub
APPENDIX 3
For these unfamiliar with Excel’s VBA, this AI-generated tutorial ought to be useful.
The publish Clearing out the info litter appeared first on EDN.