在wpf中绘制图形

时间:2013-09-27 06:34:44

标签: c# wpf plot 2d

好的,这可能很简单,所以请原谅我,但我真的被卡住了。

我有两个2D线图需要在wpf上绘制,每个都有2组数组。

第一张图的数组是

 x1=[0.5,0.509999999776483,0.519999999552965,0.529999999329448,0.53999999910593,0.549
    999998882413,0.559999998658895,0.569999998435378,0.579999998211861,0.58999999798
    8343,0.599999997764826,0.609999997541308,0.619999997317791,0.629999997094274,0.6
    39999996870756,0.649999996647239,0.659999996423721,0.669999996200204,0.679999995
    976686,0.689999995753169,0.699999995529652,0.709999995306134,0.719999995082617,0
    .729999994859099,0.739999994635582,0.749999994412065,0.759999994188547,0.7699999
    9396503,0.779999993741512,0.789999993517995,0.799999993294477,0.80999999307096,0
    .819999992847443,0.829999992623925,0.839999992400408,0.84999999217689,0.85999999
    1953373,0.869999991729856,0.879999991506338,0.889999991282821,0.899999991059303,
    0.909999990835786,0.919999990612268,0.929999990388751,0.939999990165234,0.949999
    989941716,0.959999989718199,0.969999989494681,0.979999989271164,0.98999998904764
    7,0.999999988824129,0]

    y1=[0.0297619047619048,0.0303571428438382,0.0309523809257717,0.0315476190077052,0.03
    21428570896387,0.0327380951715722,0.0333333332535057,0.0339285713354392,0.034523
    8094173727,0.0351190474993061,0.0357142855812396,0.0363095236631731,0.0369047617
    451066,0.0374999998270401,0.0380952379089736,0.0386904759909071,0.03928571407284
    06,0.039880952154774,0.0404761902367075,0.041071428318641,0.0416666664005745,0.0
    42261904482508,0.0428571425644415,0.043452380646375,0.0440476187283085,0.0446428
    568102419,0.0452380948921754,0.0458333329741089,0.0464285710560424,0.04702380913
    79759,0.0476190472199094,0.0482142853018429,0.0488095233837763,0.049404761465709
    8,0.0499999995476433,0.0505952376295768,0.0511904757115103,0.0517857137934438,0.
    0523809518753773,0.0529761899573108,0.0535714280392442,0.0541666661211777,0.0547
    619042031112,0.0553571422850447,0.0559523803669782,0.0565476184489117,0.05714285
    65308452,0.0577380946127787,0.0583333326947121,0.0589285707766456,0.059523808858
    5791,0]

第二张图

x2=[6,27.3000000789762,27.4000000804663,27.5000000819564,27.6000000834465,27.7000000
849366,27.8000000864267,27.9000000879169,28.000000089407,28.1000000908971,28.200
0000923872,28.3000000938773,28.4000000953674,28.5000000968575,28.6000000983477,2
8.7000000998378,28.8000001013279,28.900000102818,29.0000001043081,29.10000010579
82,29.2000001072884,29.3000001087785,29.4000001102686,29.5000001117587,29.600000
1132488,29.7000001147389,29.8000001162291,29.9000001177192,30.0000001192093,30.1
000001206994,30.2000001221895,30.3000001236796,30.4000001251698,30.5000001266599
,30.60000012815,30.7000001296401,30.8000001311302,30.9000001326203,31.0000001341
105,31.1000001356006,31.2000001370907,31.3000001385808,31.4000001400709,31.50000
0141561,31.6000001430511,31.7000001445413,31.8000001460314,31.9000001475215,32.0
000001490116,32.1000001505017,32.2000001519918,32.300000153482,32.4000001549721,
32.5000001564622,32.6000001579523,32.7000001594424,32.8000001609325,32.900000162
4227,33.0000001639128,33.1000001654029,33.200000166893,33.3000001683831,33.40000
01698732,33.5000001713634,33.6000001728535,33.7000001743436,33.8000001758337,33.
9000001773238,34.0000001788139,34.1000001803041,34.2000001817942,34.300000183284
3,34.4000001847744,34.5000001862645,34.6000001877546,34.7000001892447,34.8000001
907349,34.900000192225,35.0000001937151,35.1000001952052,35.2000001966953,35.300
0001981854,35.4000001996756,35.5000002011657,35.6000002026558,35.7000002041459,3
5.800000205636,35.9000002071261,36.0000002086163,36.1000002101064,36.20000021159
65,36.3000002130866,36.4000002145767,36.5000002160668,36.600000217557,36.7000002
190471,36.8000002205372,36.9000002220273,37.0000002235174,37.1000002250075,37.20
00002264977,37.3000002279878,37.4000002294779,37.500000230968,37.6000002324581,3
7.7000002339482,37.8000002354383,37.9000002369285,38.0000002384186,38.1000002399
087,38.2000002413988,38.3000002428889,38.400000244379,38.5000002458692,38.600000
2473593,38.7000002488494,38.8000002503395,38.9000002518296,39.0000002533197,39.1
000002548099,39.2000002563,39.3000002577901,39.4000002592802,39.5000002607703,39
.6000002622604,39.7000002637506,39.8000002652407,39.9000002667308]



y2=[93004,798.969435963394,793.231792438482,787.555733374873,781.940380567453,776.38
487140968,770.888358562288,765.450009630173,760.069006847227,754.744546768901,74
9.475839972283,744.262110763467,739.102596892038,733.996549272446,728.9432317121
06,723.941920646016,718.991904877732,714.092485326527,709.242974780542,704.44269
7655806,699.690989760928,694.987198067333,690.330680484888,685.720805642766,681.
156952675422,676.63851101353,672.164880179763,667.735469589285,663.34969835482,6
59.0069950962,654.706797754254,650.448553408935,646.231718101576,642.05575666116
4,637.920142534532,633.824357620366,629.767892106931,625.750244313418,621.770920
534824,617.829434890278,613.92530917471,610.058072713803,606.227262222124,602.43
2421664368,598.673102119631,594.948861648638,591.25926516385,587.60388430239,583
.9822973017,580.394088877881,576.838850106633,573.316178306746,569.825676926072,
566.366955429918,562.939629191806,559.543319386533,556.17765288549,552.842262154
178,549.536785151859,546.260865233313,543.014151052629,539.796296469,536.6069604
54459,533.445807003518,530.312505044672,527.206728353705,524.128155468783,521.07
6469607258,518.051358584182,515.052514732459,512.079634824617,509.132419996147,5
06.210575670395,503.313811484947,500.441841219489,497.594382725105,494.771157854
972,491.971892396437,489.19631600443,486.444162136185,483.715167987252,481.00907
442875,478.325625945857,475.664570577489,473.025659857156,470.408648754955,467.8
13295620699,465.239362128119,462.686613220158,460.154817055303,457.643744954941,
455.153171351719,452.682873738891,450.232632620615,447.802231463197,445.39145664
7245,443.000097420736,440.627945852945,438.27479678925,435.940447806771,433.6246
99170839,431.327353792267,429.048217185413,426.787097427022,424.543805115817,422
.318153332836,420.109957602493,417.919035854351,415.745208385592,413.58829782416
7,411.44812909261,409.324529372512,407.217328069634,405.12635677964,403.05144925
4454,400.992441369213,398.949171089808,396.921478441008,394.909205475143,392.912
19624135,390.930296755351,388.963354969769,387.011220744972,385.073745820412]

使用matplotlib中的Plot函数在python中非常容易,但画布并没有真正显示我的结果。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

Here你有一些图书馆可以做你想做的事。就个人而言,我使用的是OxyPlot而不是内置的WPF图(太慢且未优化)。它可以在CodePlex和nuget。

上找到
     xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf" 


<oxy:Plot>
    <oxy:LineSeries ItemsSource="{Binding Path=Points}" DataFieldX="X" DataFieldY="Y" />
</oxy:Plot>

在视图模型中:

 List<Point> points = new List<Point>();
    public IEnumerable<Point> Points {
        get { return points; } 
    }

答案 1 :(得分:1)

我正在使用SworfishCharts来渲染我的图形,基于这个项目: http://www.codeproject.com/Articles/17097/WPF-Chart-Control-With-Pan-Zoom-and-More

你可能想看看它。