Skip to content

Commit 0b59416

Browse files
committed
Add .transport.plot.Scale1Diff
1 parent 3905b90 commit 0b59416

File tree

1 file changed

+42
-0
lines changed
  • message_ix_models/model/transport

1 file changed

+42
-0
lines changed

message_ix_models/model/transport/plot.py

+42
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,48 @@ def generate(self, y0: int, data):
662662
yield ggplot
663663

664664

665+
class Scale1Diff(Plot):
666+
"""scale-1 factor in y=2020; changes between 2 scenarios."""
667+
668+
basename = "scale-1-diff"
669+
670+
runs_on_solved_scenario = False
671+
inputs = ["scale-1:nl-t-c-l-h:a", "scale-1:nl-t-c-l-h:b"]
672+
673+
_s, _v, _y = "scenario", "value", "t + ' ' + c"
674+
static = Plot.static + [
675+
p9.aes(x=_v, y=_y, yend=_y, group=_s, color=_s, shape=_s),
676+
p9.facet_wrap("nl", scales="free_x"),
677+
p9.geom_vline(p9.aes(xintercept=_v), pd.DataFrame([[1.0]], columns=[_v])),
678+
p9.geom_point(),
679+
p9.scale_shape(unfilled=True),
680+
p9.scale_x_log10(),
681+
p9.labs(x="", y="Mode × commodity"),
682+
]
683+
684+
def generate(self, data_a, data_b):
685+
# Data for plotting points
686+
df0 = (
687+
pd.concat([data_a.assign(scenario="a"), data_b.assign(scenario="b")])
688+
.drop(["l", "h", "unit"], axis=1)
689+
.query("nl != 'R12_GLB'")
690+
)
691+
# Data for plotting segments/arrows
692+
df1 = (
693+
df0.pivot(columns="scenario", index=["nl", "t", "c"])
694+
.set_axis(["value", "xend"], axis=1)
695+
.reset_index()
696+
.assign(scenario="diff")
697+
)
698+
699+
return (
700+
p9.ggplot(df0)
701+
+ p9.geom_segment(p9.aes(xend="xend"), df1, arrow=p9.arrow(length=0.03))
702+
+ self.static
703+
+ self.ggtitle()
704+
)
705+
706+
665707
class Stock0(Plot):
666708
"""LDV transport vehicle stock."""
667709

0 commit comments

Comments
 (0)