python中的频率绘图

时间:2015-10-08 16:58:33

标签: python graph plot frequency

我需要一些指导来进行简单的绘图。有很多库,但我找不到这个特定的图表。 我有两个数组,一个保存值,另一个保存这些值的频率。

例如:

x = [1,2,3,4,5]
y = [10,40,30,10,3]

我想制作一个我的值的图表 - x,与他们的频率相比。优选地,图形列将被填充而不是单独的点。

R中的等价物将指定一个向量A 10个元素1个,40个元素2个,30个元素3个,10个元素4个,3个元素5个,并使用图表(表(A))< / p>

1 个答案:

答案 0 :(得分:0)

使用matplotlib&#39; s bar

Sub Macro1()

Dim MyFileName As String, MyPath As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
MyPath = "C:\testfiles\"
MyFileName = Dir(MyPath & "*.xls*")
Do Until MyFileName = ""
Workbooks.Open Filename:=MyPath & MyFileName

Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets

        If ws.Name Like "*Ont*" Then
            ws.Activate
            LastRow1 = ActiveSheet.UsedRange.Row - 1 +     ActiveSheet.UsedRange.Rows.Count
            strAddress2 = "T2:T" & LastRow1
            wbName = ThisWorkbook.Name
            Range(strAddress2).Value = Left(wbName, InStrRev(wbName, ".") - 1)

        End If
    Next
 wbName = Left(ThisWorkbook.Name, InStr(1, ThisWorkbook.Name, ".") - 1)
 LastRow = Sheets(wbName).Range("A" & Rows.Count).End(xlUp).Row
 Sheets.Add Type:=xlWorksheet
 ActiveSheet.Name = "DataSummary2"
 For i = 2 To LastRow
 If Sheets(wbName).Cells(i, "A").Value = "ON" Then
 Sheets(wbName).Cells(i, "E").EntireRow.Copy Destination:=Sheets("DataSummary2").Range("A" & Rows.Count).End(xlUp).Offset(1)
 End If
 Next i


    MyFileName = Dir
    ActiveWorkbook.Close True
Loop

End Sub

enter image description here