Skip to content
Vega-Lite templates

Linear Program — Feasible Region

Two-variable LP feasible region with the optimal vertex highlighted.

Template previewVega-Lite
Rendering…

Make it your own.

{
  "$schema":"https://vega.github.io/schema/vega-lite/v5.json",
  "data":{"values":[
    {"x":0,"y":0,"r":"feasible"},
    {"x":0,"y":4,"r":"feasible"},
    {"x":2,"y":4,"r":"feasible"},
    {"x":4,"y":2,"r":"feasible"},
    {"x":4,"y":0,"r":"feasible"},
    {"x":4,"y":2,"k":"optimal"}
  ]},
  "layer":[
    {"transform":[{"filter":"datum.r === 'feasible'"}],
     "mark":{"type":"area","color":"#dbeafe","opacity":0.6,"line":{"color":"#3666ff","strokeWidth":2}},
     "encoding":{
       "x":{"field":"x","type":"quantitative","title":"x","scale":{"domain":[0,5]}},
       "y":{"field":"y","type":"quantitative","title":"y","scale":{"domain":[0,5]}},
       "order":{"value":0}
     }},
    {"transform":[{"filter":"datum.k === 'optimal'"}],
     "mark":{"type":"point","filled":true,"size":240,"color":"#dc2626"},
     "encoding":{
       "x":{"field":"x","type":"quantitative"},
       "y":{"field":"y","type":"quantitative"},
       "tooltip":[{"field":"x"},{"field":"y"}]
     }}
  ],
  "width":380,"height":380
}