Home > Net >  matplotlib-cpp connecting first and last point in the data set
matplotlib-cpp connecting first and last point in the data set

Time:04-22

I was able to link matplotlib-cpp to visual studio. When I set the data and plot it everything works fine except first point and last point gets connected. I know that the first point and last point is not the same. My code

#include <iostream>
#include <vector>
#include <cstdio>
#include "matplotlibcpp.h" 

namespace plt = matplotlibcpp;

int main()
{
    FILE *fp1;

    fp1 = fopen("data1.tmp", "r"); 
    int num = 139;
    std::vector<double> xval(num   1), yval(num   1);

    i = 0;
    while (i < num)
    {
        fscanf(fp1, "%lf \t %lf\n", &xval[i], &yval[i]);
        i  ;
    }

    fclose(fp1);

    plt::figure_size(1200, 780);
    plt::plot(xval,y1val,"r--");
    plt::show();
}

My list of data

0.000000     0.000000
0.005000     0.005000
0.010000     0.010000
0.015000     0.014999
0.020000     0.019999
0.025000     0.024997
0.030000     0.029996
0.035000     0.034993
0.040000     0.039989
0.045000     0.044985
0.050000     0.049979
0.055000     0.054972
0.060000     0.059964
0.065000     0.064954
0.070000     0.069943
0.075000     0.074930
0.080000     0.079915
0.085000     0.084898
0.090000     0.089879
0.095000     0.094857
0.100000     0.099833
0.105000     0.104807
0.110000     0.109778
0.115000     0.114747
0.120000     0.119712
0.125000     0.124675
0.130000     0.129634
0.135000     0.134590
0.140000     0.139543
0.145000     0.144492
0.150000     0.149438
0.155000     0.154380
0.160000     0.159318
0.165000     0.164252
0.170000     0.169182
0.175000     0.174108
0.180000     0.179030
0.185000     0.183947
0.190000     0.188859
0.195000     0.193767
0.200000     0.198669
0.205000     0.203567
0.210000     0.208460
0.215000     0.213347
0.220000     0.218230
0.225000     0.223106
0.230000     0.227978
0.235000     0.232843
0.240000     0.237703
0.245000     0.242556
0.250000     0.247404
0.255000     0.252245
0.260000     0.257081
0.265000     0.261909
0.270000     0.266731
0.275000     0.271547
0.280000     0.276356
0.285000     0.281157
0.290000     0.285952
0.295000     0.290740
0.300000     0.295520
0.305000     0.300293
0.310000     0.305059
0.315000     0.309816
0.320000     0.314567
0.325000     0.319309
0.330000     0.324043
0.335000     0.328769
0.340000     0.333487
0.345000     0.338197
0.350000     0.342898
0.355000     0.347590
0.360000     0.352274
0.365000     0.356949
0.370000     0.361615
0.375000     0.366273
0.380000     0.370920
0.385000     0.375559
0.390000     0.380188
0.395000     0.384808
0.400000     0.389418
0.405000     0.394019
0.410000     0.398609
0.415000     0.403190
0.420000     0.407760
0.425000     0.412321
0.430000     0.416871
0.435000     0.421410
0.440000     0.425939
0.445000     0.430458
0.450000     0.434966
0.455000     0.439462
0.460000     0.443948
0.465000     0.448423
0.470000     0.452886
0.475000     0.457338
0.480000     0.461779
0.485000     0.466208
0.490000     0.470626
0.495000     0.475032
0.500000     0.479426
0.505000     0.483807
0.510000     0.488177
0.515000     0.492535
0.520000     0.496880
0.525000     0.501213
0.530000     0.505533
0.535000     0.509841
0.540000     0.514136
0.545000     0.518418
0.550000     0.522687
0.555000     0.526943
0.560000     0.531186
0.565000     0.535416
0.570000     0.539632
0.575000     0.543835
0.580000     0.548024
0.585000     0.552199
0.590000     0.556361
0.595000     0.560509
0.600000     0.564642
0.605000     0.568762
0.610000     0.572867
0.615000     0.576959
0.620000     0.581035
0.625000     0.585097
0.630000     0.589145
0.635000     0.593178
0.640000     0.597195
0.645000     0.601198
0.650000     0.605186
0.655000     0.609159
0.660000     0.613117
0.665000     0.617059
0.670000     0.620986
0.675000     0.624897
0.680000     0.628793
0.685000     0.632673
0.690000     0.636537
0.695000     0.640385
0.700000     0.644218 

and here is the result

graph

How do I remove that annoying line?

CodePudding user response:

These two lines:

int num = 139;
std::vector<double> xval(num   1), yval(num   1);

create vectors xval and yval of 140 double elements initialized to 0.

You only load 139 points from your dataset and the first point in the dataset is (0,0); so your first (0-th) and last (139-th) points are indeed equal. You may try:

int num = 139;
std::vector<double> xval(num), yval(num);
  • Related