如何绘制在Mathematica中容易修改且简单完成的分叉图?

时间:2018-09-18 23:34:32

标签: graphics wolfram-mathematica

我有许多分支图可以做,所以我想做一些容易修改的事情。随附的代码是初次尝试。

p1 = Plot[{Sqrt[a], -Sqrt[a]}, {a, -3, 6}];
horiz = Graphics@
  Line[ {{-3, 2}, {6, 2}} ];(*horizontal line at y=2 *)
horiz2 = Graphics@
  Line[ {{-3, -2}, {6, -2}} ];(*horizontal line at y=2 *)
vertm = Graphics@
  Line[ {{-1, -2}, {-1, 2}} ];(*vertical line at a=-1 *)
vert0 = Graphics@
  Line[ {{  0, -2}, {0, 2}} ];(*vertical line at a=0 *)
vert1 = Graphics@
  Line[ {{  1, -2}, {1, 2}} ];(*vertical line at a=1 *)
vert2 = Graphics@
  Line[ {{  2, -2}, {2, 2}} ];(*vertical line at a=21 *)
vert3 = Graphics@
  Line[ {{  3, -2}, {3, 2}} ];(*vertical line at a=3 *)
vert4 = Graphics@
  Line[ {{  4, -2}, {4, 2}} ];(*vertical line at a=4 *)
vert5 = Graphics@
  Line[ {{  5, -2}, {5, 2}} ];(*vertical line at a=5 *)
Show[p1, horiz, horiz2, vertm, vert0, vert1, vert2, vert3, vert4, \
vert5] 

我希望所有抛物线都为红色,而不是蓝色和金色,并以粗体显示,以便脱颖而出。最好在下面标记每条垂直线,例如a = 1。你能帮我吗?谢谢。

此致, MM

3 个答案:

答案 0 :(得分:1)

对于大胆的红色抛物线:

var Ref: DatabaseReference!
Ref = Database.database().reference()

Ref.child("posts").queryOrdered(byChild: "postTimeStamp").observeSingleEvent(of: .value) { (snapshot) in

    for child in snapshot.children {

        let snap = child as! DataSnapshot
        let dict = snap.value as! [String: Any]

        // set all additional information and append to array

        self.collectionView?.reloadData()

    }

}

要标记垂直线:

var Ref: DatabaseReference!
Ref = Database.database().reference()

Ref.child("posts").queryOrdered(byChild: "postTimeStamp").observeSingleEvent(of: .value) { (snapshot) in

    for child in snapshot.children {

        let snap = child as! DataSnapshot
        let dict = snap.value as! [String: Any]

        Ref.child("users").child(dict["userID"] as! String).observeSingleEvent(of: .value, with: { (snapUser) in

            let valueUser = snapUser.value as! [String: Any]

            // set all additional information and append to array

            self.collectionView?.reloadData()

        }

    }

}

您可以使用p1 = Plot[{Sqrt[a], -Sqrt[a]}, {a, -3, 6}, PlotStyle -> {{Red, Thickness[0.01]}, {Red, Thickness[0.01]}}]; 来简化垂直线的生成。

vert1 = Graphics@{Line[{{1, -2}, {1, 2}}], Text["a = 1", {1, 2}]};
vert2 = Graphics@{Line[{{2, -2}, {2, 2}}], Text["a = 2", {2, 2}]};

enter image description here

答案 1 :(得分:1)

根据您的评论,我认为这更像是您要尝试的事情。

verticalLines[xmin_, xmax_, step_] := 
 Table[Graphics@{Line[{{x, -2}, {x, 2}}], 
    Text["a = " <> ToString[x], {x, 2.2}], PointSize[Large], 
    Point[{x, -2}], Point[{x, 2}]}, {x, xmin, xmax, step}]

p1 = Plot[{Sqrt[a], -Sqrt[a]}, {a, -3, 6}, 
   PlotStyle -> {{Red, Thickness[0.01]}, {Red, Thickness[0.01]}}];

Show[p1, verticalLines[-1, 5, 1]]

enter image description here

答案 2 :(得分:1)

p1 = Plot[{0, -a}, {a, -4, 4}, PlotRange -> {-4, 4}, 
   AxesLabel -> {"a", "y=f_a(y)=dy/dt"}, 
   PlotStyle -> {   {Red, Thickness[0.007]}, {Red, 
      Thickness[0.005]}  }];
vertm3 = Graphics@{Line[{ {-3, -3.5}, {-3, 3.0} }], 
    Text["a = -3", {-3, 3.5}]};
vertm2 = Graphics@{Line[{ {-2, -3.5}, {-2, 3.0} }], 
    Text["a = -2", {-2, 3.5}]};
vertm =  Graphics@{Line[{ {-1, -3.5}, {-1, 3.0} }], 
    Text["a = -1", {-1, 3.5}]};
vert0 =   
  Graphics@{Line[{ {  0, -3.5}, {  0, 3.0} }], 
    Text[  "a = 0", {0, 3.5}]};
vert1 =  Graphics@{Line[{ {   1, -3.5}, {  1, 3.0} }], 
    Text[  "a = 1", {1, 3.5}]};
vert2 =  Graphics@{Line[{ {   2, -3.5}, {  2, 3.0} }], 
    Text[  "a = 2", {2, 3.5}]};
vert3 =  Graphics@{Line [{ {  3, -3.5}, {  3, 3.0} }], 
    Text[  "a = 3", {3, 3.5}]};   
Show[p1, vertm3, vertm2, vertm, vert0, vert1, vert2, vert3, 
 Epilog -> {PointSize -> Large,
         Point[{{-3, 0}, {-3, 3}, {-2, 0}, {-2, 2}, {-1, 0}, {-1, 
      1}, {0, 0}, {1, 0}, {1, -1}, {2, 0}, {2, -2}, {3, 
      0}, {3, -3}}] }]