Dictionary series and color cycles
# Loop through series in insertion order; style colors rotate automatically.page=canvas(size=(130mm,90mm),background="#ffffff")series={"Baseline":[1,2,3,3.5],"Annealed":[1.2,2.8,3.1,4],"Cold worked":[2,2.2,2.8,3.1]}style=plot_style(colors=palette("tab10"),font_family="DejaVu Sans",font_size=8pt)chart=plot(size=(120mm,80mm),style=style,x=axis(label="Time",range=(0,3)),y=axis(label="Response",range=(0,5)))for name,ys in series.items() { chart.line(x=[0,1,2,3],y=ys,label=name,marker="circle")}chart.legend(position="top_left")page.add(chart,offset=(5mm,5mm))# Loop through series in insertion order; style colors rotate automatically.page=canvas(size=(130mm,90mm),background="#ffffff")series={"Baseline":[1,2,3,3.5],"Annealed":[1.2,2.8,3.1,4],"Cold worked":[2,2.2,2.8,3.1]}style=plot_style(colors=palette("tab10"),font_family="DejaVu Sans",font_size=8pt)chart=plot(size=(120mm,80mm),style=style,x=axis(label="Time",range=(0,3)),y=axis(label="Response",range=(0,5)))for name,ys in series.items() { chart.line(x=[0,1,2,3],y=ys,label=name,marker="circle")}chart.legend(position="top_left")page.add(chart,offset=(5mm,5mm))"""Python dictionary binding; run from the repository root with PYTHONPATH=python.Outputs and the reproducible .lay source are written to dictionary-output/."""from pathlib import Pathfrom laymesh import render_source HERE = Path(__file__).resolve().parentseries = { "Baseline": [1, 2, 3, 3.5], "Annealed": [1.2, 2.8, 3.1, 4], "Cold worked": [2, 2.2, 2.8, 3.1],}source = "\n".join( "series = {{series}}" if line.startswith("series=") else line for line in HERE.joinpath("dictionary-series.lay").read_text().splitlines())output = HERE / "dictionary-output"output.mkdir(exist_ok=True)result = render_source( source, namespace={"series": series}, base_dir=output, output=output / "series.pdf", save_source="series.lay",)print(result.saved_source)Preview
Background
Dependencies
examples/plot/dictionary-series.lay
Reproduce
laymesh validate examples/plot/dictionary-series.laylaymesh render examples/plot/dictionary-series.lay -o figure.svglaymesh render examples/plot/dictionary-series.lay -o figure.pdflaymesh render examples/plot/dictionary-series.lay -o figure.png --dpi 300