2
$\begingroup$

I am trying to plot 3 sets of points. For example consider

Xfinal={{79.7752, -4.5745}, {79.7752, -4.57458}, {79.7751, -4.57453},
{79.8622, -4.36018}, {79.8621, -4.36023}, {79.8623, -4.36031},
{79.5962, -4.39891}, {79.5962, -4.39893}, {79.5962, -4.3989}}

I am making it into three sets:

Xfinala = Xfinal[[1 ;; 3, All]]
Xfinalb = Xfinal[[4 ;; 6, All]]
Xfinalc = Xfinal[[7 ;; 9, All]]

I am using the following commands to plot:

Plotx = ListPlot[Xfinala, PlotStyle -> {Thick, Red}]
Ploty = ListPlot[Xfinalb, PlotStyle -> {Thick, Green}]
Plotz = ListPlot[Xfinalc, PlotStyle -> {Thick, Blue}]
Plot1 = Show[Plotx, Ploty, Plotz]

Further, let

βa={-157.767, 1.42204, -9.90731} 
βb={-649.437, 7.96711, -3.24825}

Now I am trying to plot the following lines together with points using the following codes:

Plotsvma = 
 Plot[-(1/βa[[2]])*(βa[[2]]*x + βa[[1]]) , {x, -10, 10}]
Plotsvmb = 
 Plot[-(1/βb[[3]])*(βb[[2]]*x + βb[[1]]) , {x, -10, 10}]

and finally:

Plotx = Show[Plot1, Plotsvma , Plotsvmb ]

But it is not displaying all the plots... Am I doing something wrong?

$\endgroup$
  • 1
    $\begingroup$ add PlotRange->All to Show . $\endgroup$ – kglr Jul 22 '18 at 8:52
  • $\begingroup$ Note that the because of very different scales in Plots and ListPlots all three points overlap in the output of Show. $\endgroup$ – kglr Jul 22 '18 at 8:53
3
$\begingroup$

Ok, your problem is the incompatible PlotRange of the plots you are trying to Show, that you can fix by hand or with PlotRange->All in Show as suggested by @kglr, while I was typing this answer.

I would do other things differently as well.

Xfinal = {{79.7752, -4.5745}, {79.7752, -4.57458}, {79.7751, \
-4.57453}, {79.8622, -4.36018}, {79.8621, -4.36023}, {79.8623, \
-4.36031}, {79.5962, -4.39891}, {79.5962, -4.39893}, {79.5962, \
-4.3989}}

Do a single ListPlot using Partition and Thread to avoid repeating code.

plot1 = ListPlot[
   Partition[Xfinal, 3]
   , PlotTheme -> "Scientific"
   , PlotStyle -> Thread@{PointSize[Large], {Red, Green, Blue}}
   ];

Limit the use of global variables, using limited scope functions such as With

plotsvm = With[
   {
    βa = {-157.767, 1.42204, -9.90731},
    βb = {-649.437, 7.96711, -3.24825}
    },
   Plot[
    {
     -(1/βa[[2]])*(βa[[2]]*x + βa[[1]]),
     -(1/βb[[3]])*(βb[[2]]*x + βb[[1]])
     }
    , {x, 75, 95}
    , PlotTheme -> "Scientific"
    , FrameTicks -> True
    ]];


Show[plotsvm, plot1]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Hi, This is good. I reccomend a small change {x, (Min /@ Transpose[Xfinal])[[2]], (Max /@ Transpose[Xfinal])[[1]]} instead of {x, 75, 95}. $\endgroup$ – kosa Jul 23 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.