Plottest du das direkt aus AutoIt heraus? Falls ja - wie?
Da muss ich dich direkt vorwarnen, das folgende ist keine UDF die es in die Öffentlichkeit geschafft hat. Sie ist in keinem guten Zustand und jedes Mal, wenn ich etwas plotten will baue ich genau die funktion die ich gerade brauche ein^^
AutoIt
#include-once
#include <GDIPlus.au3>
#include <Array.au3>
Global $__AG_OPT_WITH_LINES = True
Global $__AG_OPT_WITH_POINTS = True
Global $__AG_OPT_LOGSCALE_Y = False
Global $__AG_XMIN = 0
Global $__AG_XMAX = 1
Func _ArrayGraph_SetXRange($fMin, $fMax)
$__AG_XMIN = $fMin
$__AG_XMAX = $fMax
EndFunc
;~ Local $a = [1, 2, 3, 2, 1.5, 6.3, 1, 0, 0, -2, 1.123, 2.345, 3, 2, 1, 2, 3, 5, 4, 3, 2, 1, 0, -1, -2, 5, 4, 3, 2, 1, 9, -2.22, -1, 3, 2.1, 4]
;~ ArrayGraph1D($a)
;~ Local $b = [1000, 1001, 998, 995, 1013.2, 995.5]
;~ ArrayGraph1D($b)
If @ScriptName = 'ArrayGraph1D.au3' Then
Local $c = CreateCosArray(4 * 8)
_ArrayGraph($c, '', 0, 0, lin)
EndIf
Func lin($x)
Return 2 + $x / 3
EndFunc ;==>lin
Func CreateCosArray($iSize = 8, $xFunc = _Cos)
Local $a[$iSize]
For $i = 0 To $iSize - 1 Step 1
$a[$i] = $xFunc($i / ($iSize - 1) * 6.28318530717959)
Next
Return $a
EndFunc ;==>CreateCosArray
Func __Cos($x)
Return _Cos($x / (4 * 8 - 1) * 6.28318530717959)
EndFunc ;==>__Cos
Func _Cos($x)
Local $a = 1
Local $b = 2
Local $c = 3
Local $d = 1
Return $a * (Cos($x) + 1) + $b * (Cos(2 * $x) + 1) + $c * (Cos(4 * $x) + 1) + $d * (Cos(8 * $x) + 1)
EndFunc ;==>_Cos
Func __AG_ArrayMinMax(ByRef $aArray, $iFrom = 0, $iTo = 0)
Local $iMax = Null, $iMin = Null
If $iTo = 0 Then $iTo = UBound($aArray) - 1
For $i = $iFrom To $iTo Step 1
If __AG_IsInf($aArray[$i]) Then ContinueLoop
If $iMin = Null Then $iMin = $aArray[$i]
If $iMax = Null Then $iMax = $aArray[$i]
If $aArray[$i] < $iMin Then $iMin = $aArray[$i]
If $aArray[$i] > $iMax Then $iMax = $aArray[$i]
Next
Local $aRet = [$iMin, $iMax]
Return $aRet
EndFunc ;==>__AG_ArrayMinMax
Func __AG_FuncMinMax(ByRef $xFunc, $iFrom, $iTo)
If Not IsFunc($xFunc) Then Return SetError(1, 0, '__Ag_FuncMinMax called, but $xFunc is no function.')
Local $iMax = Null, $iMin = Null, $x
For $i = $iFrom To $iTo Step 1
$x = $__AG_OPT_LOGSCALE_Y ? Log($xFunc($i)) : $xFunc($i)
If __AG_IsInf($xFunc($i)) Then ContinueLoop
If $iMin = Null Then $iMin = $x
If $iMax = Null Then $iMax = $x
If $x < $iMin Then $iMin = $x
If $x > $iMax Then $iMax = $x
Next
Local $aRet = [$iMin, $iMax]
Return $aRet
EndFunc ;==>__AG_FuncMinMax
Func __AG_IsInf($x)
Return $x = -1 / 0 Or $x = 1 / 0
EndFunc ;==>__AG_IsInf
Func __AG_BeautifyNumber($x)
If $x > 999.9 Then Return StringTrimRight(StringFormat('%.2e', $x), 4) & StringTrimLeft(StringSplit(StringFormat('%.2e', $x), 'e', 2)[1], 2)
If $x > 99.99 Then Return StringFormat('%.1f', $x)
If $x > 9.999 Then Return StringFormat('%.2f', $x)
If $x > 0.999 Then Return StringFormat('%.3f', $x)
;~ ConsoleWrite($x & ' ' & StringFormat('%.2e', $x) & @CRLF)
Return StringTrimRight(StringFormat('%.2e', $x), 4) & '-' & StringTrimLeft(StringSplit(StringFormat('%.2e', $x), 'e', 2)[1], 2)
EndFunc ;==>__AG_BeautifyNumber
Func __AG_PointDistance($x1, $y1, $x2, $y2)
Return Sqrt(($x1 - $x2) ^ 2 + ($y1 - $y2) ^ 2)
EndFunc ;==>__AG_PointDistance
Func Swap(ByRef $x, ByRef $y)
Local $t = $x
$x = $y
$y = $t
EndFunc ;==>Swap
Func _ArrayGraph($aArray, $sTitle = Default, $iFrom = 0, $iTo = 0, $xFunc = 0)
If UBound($aArray) = 1 Then Return SetError(1, 0, 'Array contains only 1 element') ; TODO
If UBound($aArray, 0) <> 1 Then Return SetError(2, 0, 'Array must be 1D')
Local $bFunc = IsFunc($xFunc)
Local $iUBound = UBound($aArray)
If $iTo = 0 Then $iTo = $iUBound - 1
If $iFrom < 0 Then $iFrom = 0
If $iFrom > $iTo Then Swap($iFrom, $iTo)
Local $sOldOpt = __AG_SetMultiOpt('GUIOnEventMode = 0; MouseCoordMode = 2')
Local $iW = 800, $iH = 400
Local $hGUI = GUICreate((($sTitle = Default) Or (Not $sTitle)) ? ('Array[' & $iUBound & '] Range: [' & $iFrom & ']-[' & $iTo & ']') : $sTitle, $iW, $iH)
Local $hOldGUI = GUISwitch($hGUI)
If $__AG_OPT_LOGSCALE_Y Then
For $i = $iFrom To $iTo Step 1
$aArray[$i] = Log($aArray[$i])
Next
EndIf
Local $aPositions[$iUBound][2]
_GDIPlus_Startup()
Local $hGFX = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hBMP = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGFX)
Local $hBUF = _GDIPlus_ImageGetGraphicsContext($hBMP)
Local $hBMP_BG = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGFX)
Local $hBUF_BG = _GDIPlus_ImageGetGraphicsContext($hBMP_BG)
_GDIPlus_GraphicsSetSmoothingMode($hBUF_BG, 2)
_GDIPlus_GraphicsSetSmoothingMode($hBUF, 2)
_GDIPlus_GraphicsClear($hBUF_BG, 0xFF383838)
Local $hBRU = _GDIPlus_BrushCreateSolid(0xFF444444)
Local $hBRU2 = _GDIPlus_BrushCreateSolid(0xFFCC5555)
Local $hPEN = _GDIPlus_PenCreate(0xFFDDDDDD)
Local $hPEN2 = _GDIPlus_PenCreate(0xFFFF8888)
Local $aBorder = [90, 35, 10, 40] ; Layout
_GDIPlus_GraphicsDrawRect($hBUF_BG, $aBorder[0], $aBorder[1], $iW - ($aBorder[0] + $aBorder[2]), $iH - ($aBorder[1] + $aBorder[3]), $hPEN)
_GDIPlus_GraphicsFillRect($hBUF_BG, $aBorder[0], $aBorder[1], $iW - ($aBorder[0] + $aBorder[2]), $iH - ($aBorder[1] + $aBorder[3]), $hBRU)
Local $aRange = __AG_ArrayMinMax($aArray, $iFrom, $iTo)
Local $aRangeFunc = __AG_FuncMinMax($xFunc, $iFrom, $iTo)
If $aRange[0] = $aRange[1] Then
$aRange[0] -= 0.5
$aRange[1] += 0.5
EndIf
If IsArray($aRangeFunc) Then
If $aRangeFunc[0] = $aRangeFunc[1] Then
$aRangeFunc[0] -= 0.5
$aRangeFunc[1] += 0.5
EndIf
If $aRange[0] > $aRangeFunc[0] Then $aRange[0] = $aRangeFunc[0]
If $aRange[1] < $aRangeFunc[1] Then $aRange[1] = $aRangeFunc[1]
EndIf
;For $i = $iFrom To $iTo Step 1
; If __AG_IsInf($aArray[$i]) Then $aArray[$i] = $aArray[$i] > 0 ? $aRange[1] : $aRange[0]
;Next
Local $iRangeY = $aRange[1] - $aRange[0]
Local $iDotDiameter = 3.12 ^ (-0.015 * (($iTo - $iFrom) - 136)) + 1.77 ; Wenige Punkte -> Große Punkte, Viele Punkte -> Kleine Punkte
Local $tmpX, $tmpY, $tmpYFunc
Local $tRect
Local $hFAM = _GDIPlus_FontFamilyCreate('Arial')
Local $hFON = _GDIPlus_FontCreate($hFAM, 16, 0, 2)
Local $hFOR = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetLineAlign($hFOR, 1)
_GDIPlus_StringFormatSetAlign($hFOR, 2)
_GDIPlus_BrushSetSolidColor($hBRU, 0xFFAAAAAA)
For $y = $aRange[0] To $aRange[1] + 0.0001 Step $iRangeY / 10
$tmpX = $aBorder[0]
$tmpY = (1 - ($y - $aRange[0]) / $iRangeY) * ($iH - ($aBorder[1] + $aBorder[3])) + $aBorder[1]
_GDIPlus_GraphicsDrawLine($hBUF_BG, $tmpX - 5, $tmpY, $tmpX + 5, $tmpY, $hPEN)
$tRect = _GDIPlus_RectFCreate($tmpX - 5, $tmpY + 1)
_GDIPlus_GraphicsDrawStringEx($hBUF_BG, __AG_BeautifyNumber($__AG_OPT_LOGSCALE_Y ? Exp($y) : $y), $hFON, $tRect, $hFOR, $hBRU)
Next
_GDIPlus_StringFormatSetLineAlign($hFOR, 0)
_GDIPlus_StringFormatSetAlign($hFOR, 1)
Local $iCountXAxisNumbers = Int(5.85 ^ (-0.0065 * (($iTo - $iFrom) - 280)) + 12.4)
Local $tmpXOld = -1, $tmpYOld = -1, $iCountPoints = 0, $tmpYOldFunc = -1
For $x = $iFrom To $iTo Step 1
$tmpX = ($x - $iFrom) / ($iTo - $iFrom) * ($iW - ($aBorder[0] + $aBorder[2])) + $aBorder[0]
$tmpY = (1 - ($aArray[$x] - $aRange[0]) / $iRangeY) * ($iH - ($aBorder[1] + $aBorder[3])) + $aBorder[1]
If $bFunc Then $tmpYFunc = (1 - (($__AG_OPT_LOGSCALE_Y ? Log($xFunc($x)) : $xFunc($x)) - $aRange[0]) / $iRangeY) * ($iH - ($aBorder[1] + $aBorder[3])) + $aBorder[1]
$aPositions[$x][0] = $tmpX
$aPositions[$x][1] = $tmpY
If Not __AG_IsInf($aArray[$x]) Then
$iCountPoints += 1
If $__AG_OPT_WITH_LINES Then
If $iCountPoints > 1 And $x < $iTo + 1 Then
_GDIPlus_GraphicsDrawLine($hBUF_BG, $tmpXOld, $tmpYOld, $tmpX, $tmpY, $hPEN)
If $bFunc Then _GDIPlus_GraphicsDrawLine($hBUF_BG, $tmpXOld, $tmpYOldFunc, $tmpX, $tmpYFunc, $hPEN2)
EndIf
$tmpXOld = $tmpX
$tmpYOld = $tmpY
If $bFunc Then $tmpYOldFunc = $tmpYFunc
EndIf
If $__AG_OPT_WITH_POINTS Then
_GDIPlus_GraphicsDrawEllipse($hBUF_BG, $tmpX - $iDotDiameter / 2 - 2, $tmpY - $iDotDiameter / 2 - 2, $iDotDiameter + 4, $iDotDiameter + 4, $hPEN)
If $iDotDiameter > 2 Then
_GDIPlus_GraphicsFillEllipse($hBUF_BG, $tmpX - $iDotDiameter / 2, $tmpY - $iDotDiameter / 2, $iDotDiameter, $iDotDiameter, $hBRU)
If $bFunc Then _GDIPlus_GraphicsFillEllipse($hBUF_BG, $tmpX - $iDotDiameter / 2, $tmpYFunc - $iDotDiameter / 2, $iDotDiameter, $iDotDiameter, $hBRU2)
EndIf
EndIf
EndIf
If IsInt($x / Ceiling(($iTo - $iFrom) / $iCountXAxisNumbers)) Then
_GDIPlus_GraphicsDrawLine($hBUF_BG, $tmpX, $iH - $aBorder[3] + 5, $tmpX, $iH - $aBorder[3] - 5, $hPEN)
$tRect = _GDIPlus_RectFCreate($tmpX, $iH - $aBorder[3] + 6)
$tmpStr = Round($x / ($iTo - $iFrom) * ($__AG_XMAX - $__AG_XMIN) + $__AG_XMIN, 2)
_GDIPlus_GraphicsDrawStringEx($hBUF_BG, $tmpStr, $hFON, $tRect, $hFOR, $hBRU)
EndIf
Next
GUISetState(@SW_SHOW)
Local $aPos = MouseGetPos()
Local $div = ($iTo - $iFrom) / ($iW - ($aBorder[0] + $aBorder[2]))
$tRect = _GDIPlus_RectFCreate(0, 0, $iW, $aBorder[1])
_GDIPlus_FontDispose($hFON)
_GDIPlus_FontFamilyDispose($hFAM)
$hFAM = _GDIPlus_FontFamilyCreate('Consolas')
$hFON = _GDIPlus_FontCreate($hFAM, Int($aBorder[1] * 0.7), 1, 2)
_GDIPlus_StringFormatSetLineAlign($hFOR, 1)
_GDIPlus_PenSetColor($hPEN, 0xDDFFFFFF)
Local $rectX, $rectW
While GUIGetMsg() <> -3
Local $dist0 = 9999, $dist1 = 9999, $dist2 = 9999
$aPos = MouseGetPos()
_GDIPlus_GraphicsDrawImageRect($hBUF, $hBMP_BG, 0, 0, $iW, $iH)
$tmpX = Round(($aPos[0] - $aBorder[0]) / ($iW - ($aBorder[0] + $aBorder[2])) * ($iTo - $iFrom), 0)
If $tmpX >= 0 And $tmpX <= ($iTo - $iFrom) And $aPos[1] >= 0 And $aPos[1] <= $iH Then
$tmpX = Abs($tmpX)
$dist0 = __AG_PointDistance($aPos[0], $aPos[1], $aPositions[$tmpX + $iFrom][0], $aPositions[$tmpX + $iFrom][1])
If $tmpX > $iFrom Then $dist1 = __AG_PointDistance($aPos[0], $aPos[1], $aPositions[$tmpX + $iFrom - 1][0], $aPositions[$tmpX + $iFrom - 1][1])
If $tmpX < $iTo Then $dist2 = __AG_PointDistance($aPos[0], $aPos[1], $aPositions[$tmpX + $iFrom + 1][0], $aPositions[$tmpX + $iFrom + 1][1])
If $dist1 < $dist0 / 3 And $dist1 < $dist2 Then $tmpX -= 1
If $dist2 < $dist0 / 3 And $dist2 < $dist1 Then $tmpX += 1
If $tmpX + $iFrom >= UBound($aPositions) Then ContinueLoop
If $tmpX + $iFrom < 0 Then ContinueLoop
_GDIPlus_BrushSetSolidColor($hBRU, 0x20000000)
$rectX = ($tmpX - 0.5) / $div + $aBorder[0]
$rectW = 1 / $div
If $rectX < $aBorder[0] Then
$rectX = $aBorder[0]
$rectW /= 2
EndIf
If $rectX + $rectW > $iW - $aBorder[2] Then
$rectW /= 2
$rectX = $iW - $aBorder[2] - $rectW
EndIf
_GDIPlus_GraphicsFillRect($hBUF, $rectX, $aBorder[1], $rectW, $iH - ($aBorder[1] + $aBorder[3]), $hBRU)
_GDIPlus_BrushSetSolidColor($hBRU, 0xDDFFFFFF)
;~ ConsoleWrite($tmpX + $iFrom & @CRLF)
_GDIPlus_GraphicsDrawEllipse($hBUF, $aPositions[$tmpX + $iFrom][0] - $iDotDiameter / 2 - 4, $aPositions[$tmpX + $iFrom][1] - $iDotDiameter / 2 - 4, $iDotDiameter + 8, $iDotDiameter + 8, $hPEN)
If $iDotDiameter > 2 Then _GDIPlus_GraphicsFillEllipse($hBUF, $aPositions[$tmpX + $iFrom][0] - $iDotDiameter / 2, $aPositions[$tmpX + $iFrom][1] - $iDotDiameter / 2, $iDotDiameter, $iDotDiameter, $hBRU)
_GDIPlus_BrushSetSolidColor($hBRU, 0xFFDDDDDD)
_GDIPlus_GraphicsDrawStringEx($hBUF, '[' & ($tmpX + $iFrom) & '] = ' & ($__AG_OPT_LOGSCALE_Y ? Exp($aArray[$tmpX + $iFrom]) : $aArray[$tmpX + $iFrom]), $hFON, $tRect, $hFOR, $hBRU)
EndIf
_GDIPlus_GraphicsDrawImageRect($hGFX, $hBMP, 0, 0, $iW, $iH)
WEnd
_GDIPlus_BrushDispose($hBRU)
_GDIPlus_BrushDispose($hBRU2)
_GDIPlus_StringFormatDispose($hFOR)
_GDIPlus_FontDispose($hFON)
_GDIPlus_FontFamilyDispose($hFAM)
_GDIPlus_PenDispose($hPEN)
_GDIPlus_PenDispose($hPEN2)
_GDIPlus_GraphicsDispose($hBUF_BG)
_GDIPlus_BitmapDispose($hBMP_BG)
_GDIPlus_GraphicsDispose($hBUF)
_GDIPlus_BitmapDispose($hBMP)
_GDIPlus_GraphicsDispose($hGFX)
_GDIPlus_Shutdown()
__AG_SetMultiOpt($sOldOpt)
GUISwitch($hOldGUI)
GUIDelete($hGUI)
EndFunc ;==>_ArrayGraph
Func __AG_SetMultiOpt($sParam)
Local $aParam = StringSplit(StringStripWS($sParam, 8), ';', 2), $sRet, $aSplit
For $i = 0 To UBound($aParam) - 1 Step 1
$aSplit = StringSplit($aParam[$i], '=', 2)
$sRet &= $aSplit[0] & '=' & Opt($aSplit[0], $aSplit[1]) & ';'
Next
Return StringTrimRight($sRet, 1)
EndFunc ;==>__AG_SetMultiOpt
Alles anzeigen
Die Funktion gibt es eigentlich nur, weil ich im Stil von _ArrayDisplay "schnell und einfach" eine Funktion haben wollte um Arrays anzusehen. Es gibt (auch hier im Forum) UDFs die Daten plotten können, ich schätze, wenn man es ernsthaft angeht sollte man mit so einer UDF eine Anzeige basteln...
lg
M