Rotating and vertically flipping plots #529
-
I have the following code that produces the plot below. What I am in need is to get the second plot, which results from rotating the first plot and then flipping it vertically. The labels should be fixed, since they also appear rotated and flipped. I know that I could plot a brand new plot, without resorting to rotating and vertically flipping, but that would not be efficient. Is
Initial plot: Final plot: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can use #import "@preview/cetz:0.2.1"
#cetz.canvas({
import cetz.plot
import cetz.palette
import cetz.draw: *
scale(y: -1)
rotate(-90deg)
set-style(axes: (x: (label: (anchor: "north-east"), tick: (label: (anchor: "east"))),
y: (label: (anchor: "north-west"), tick: (label: (anchor: "north")))))
plot.plot(size: (5,5),
name: "plot",
x-tick-step: 2,
x-minor-tick-step: 1,
y-tick-step: 2,
y-minor-tick-step: 1,
axis-style: "school-book", {
plot.add(domain: (-0.3, 2.5),
x => 2*x,
style: palette.tango-light)
plot.add(domain: (-0.3, 2.5),
x => calc.pow(x, 2),
style: palette.tango-light)
plot.add(((2,0), (2,4)),
style: (stroke: (dash: "dashed")))
plot.add(((0,4), (2,4)),
style: (stroke: (dash: "dashed")))
plot.add-fill-between(domain: (0, 2),
x => 2*x,
x => calc.pow(x, 2),
style: (fill: aqua, stroke: black))
plot.add(((0,0), (2,4)),
mark: "o",
mark-style: (stroke: none, fill: black),
style: (stroke: none))
})
}) |
Beta Was this translation helpful? Give feedback.
-
But you could also (re-) plot with the axes swapped, which I think is the better solution: #import "@preview/cetz:0.2.1"
#cetz.canvas({
import cetz.plot
import cetz.palette
import cetz.draw: *
plot.plot(size: (5,5),
name: "plot",
x-tick-step: 2,
x-minor-tick-step: 1,
y-tick-step: 2,
y-minor-tick-step: 1,
x-label: $ y $,
y-label: $ x $,
axis-style: "school-book", {
plot.add(domain: (-0.3, 2.5),
x => 2*x,
style: palette.tango-light, axes: ("y", "x"))
plot.add(domain: (-0.3, 2.5),
x => calc.pow(x, 2),
style: palette.tango-light, axes: ("y", "x"))
plot.add(((2,0), (2,4)),
style: (stroke: (dash: "dashed")), axes: ("y", "x"))
plot.add(((0,4), (2,4)),
style: (stroke: (dash: "dashed")), axes: ("y", "x"))
plot.add-fill-between(domain: (0, 2),
x => 2*x,
x => calc.pow(x, 2),
style: (fill: aqua, stroke: black), axes: ("y", "x"))
plot.add(((0,0), (2,4)),
mark: "o",
mark-style: (stroke: none, fill: black),
style: (stroke: none), axes: ("y", "x"))
})
}) |
Beta Was this translation helpful? Give feedback.
But you could also (re-) plot with the axes swapped, which I think is the better solution: