{"id":13525169,"url":"https://github.com/Pegacraft/typst-plotting","last_synced_at":"2025-04-01T04:31:21.268Z","repository":{"id":166838787,"uuid":"642381316","full_name":"Pegacraft/typst-plotting","owner":"Pegacraft","description":"A plotting library used to draw plots and graphs in typst","archived":false,"fork":false,"pushed_at":"2024-05-22T13:06:37.000Z","size":2164,"stargazers_count":82,"open_issues_count":11,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T06:17:34.782Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Typst","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pegacraft.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-05-18T12:48:17.000Z","updated_at":"2024-07-28T16:36:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"0fcbe1d1-5033-4393-a70e-c4da8b288a7a","html_url":"https://github.com/Pegacraft/typst-plotting","commit_stats":null,"previous_names":["pegacraft/typst-plotting"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pegacraft%2Ftypst-plotting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pegacraft%2Ftypst-plotting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pegacraft%2Ftypst-plotting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pegacraft%2Ftypst-plotting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pegacraft","download_url":"https://codeload.github.com/Pegacraft/typst-plotting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222698222,"owners_count":17024879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:16.552Z","updated_at":"2025-04-01T04:31:21.261Z","avatar_url":"https://github.com/Pegacraft.png","language":"Typst","readme":"# A plotting library for Typst\n\nA Typst library for drawing graphs and plots.\nMade by Gewi413 and Pegacraffft\n\n## Currently supported graphs\n\n- Scatter plots\n\n- Graph charts\n\n- Histograms\n\n- Bar charts\n\n- Pie charts\n\n- Overlaying plots/charts\n\n  (more to come)\n\n## How to use\n\nTo use the package you can import it through this command `import \"@preview/plotst:0.2.0\": *` (as soon as the pull request first accepted).\nThe documentation is found in the `Docs.pdf` in the `docs` folder. It contains all functions necessary to use this library. It also includes a tutorial to create every available plot under their respective render methods.\n\nIf you need some example code, check out `main.typ` in the `examples` folder. It also includes a compiled version of the current `main.typ`\n\n## Examples:\n\nAll these images were created using the `main.typ`\n\n### Scatter plots\n\n```js\n    // Plot 1:\n    // The data to be displayed\n    let gender_data = (\n        (\"w\", 1), (\"w\", 3), (\"w\", 5), (\"w\", 4), (\"m\", 2), (\"m\", 2),\n        (\"m\", 4), (\"m\", 6), (\"d\", 1), (\"d\", 9), (\"d\", 5), (\"d\", 8),\n        (\"d\", 3), (\"d\", 1), (0, 11)\n    )\n\n    // Create the axes used for the chart\n    let y_axis = axis(min: 0, max: 11, step: 1, location: \"left\", helper_lines: true, invert_markings: false, title: \"foo\")\n    let x_axis = axis(values: (\"\", \"m\", \"w\", \"d\"), location: \"bottom\", helper_lines: true, invert_markings: false, title: \"Gender\")\n\n    // Combine the axes and the data and feed it to the plot render function.\n    let pl = plot(data: gender_data, axes: (x_axis, y_axis))\n    scatter_plot(pl, (100%,50%))\n\n\t// Plot 2:\n    // Same as above\n    let data = (\n        (0, 0), (2, 2), (3, 0), (4, 4), (5, 7), (6, 6), (7, 9), (8, 5), (9, 9), (10, 1)\n    )\n    let x_axis = axis(min: 0, max: 11, step: 2, location: \"bottom\")\n    let y_axis = axis(min: 0, max: 11, step: 2, location: \"left\", helper_lines: false)\n    let pl = plot(data: data, axes: (x_axis, y_axis))\n    scatter_plot(pl, (100%, 25%))\n```\n\n\n\n![scatter](./images/scatter.png)\n\n### Graph charts\n\n```js\n    // The data to be displayed\n\tlet data = (\n      (0, 0), (2, 2), (3, 0), (4, 4), (5, 7), (6, 6), (7, 9), (8, 5), (9, 9), (10, 1)\n    )\n\n    // Create the axes used for the chart\n    let x_axis = axis(min: 0, max: 11, step: 2, location: \"bottom\")\n    let y_axis = axis(min: 0, max: 11, step: 2, location: \"left\", helper_lines: false)\n\n    // Combine the axes and the data and feed it to the plot render function.\n    let pl = plot(data: data, axes: (x_axis, y_axis))\n    graph_plot(pl, (100%, 25%))\n    graph_plot(pl, (100%, 25%), rounding: 30%, caption: \"Graph Plot with caption and rounding\")\n```\n\n\n\n![graph](./images/graph.png)\n\n### Histograms\n\n```js\n\n  // Plot 1:\n  // The data to be displayed\n  let data = (\n    18000, 18000, 18000, 18000, 18000, 18000, 18000, 18000,\n    18000, 18000, 28000, 28000, 28000, 28000, 28000, 28000,\n    28000, 28000, 28000, 28000, 28000, 28000, 28000, 28000,\n    28000, 28000, 28000, 28000, 28000, 28000, 28000, 28000,\n    35000, 46000, 75000, 95000\n  )\n\n  // Classify the data\n  let classes = class_generator(10000, 50000, 4)\n  classes.push(class(50000, 100000))\n  classes = classify(data, classes)\n\n  // Create the axes used for the chart\n  let x_axis = axis(min: 0, max: 100000, step: 10000, location: \"bottom\")\n  let y_axis = axis(min: 0, max: 31, step: 5, location: \"left\", helper_lines: true)\n\n  // Combine the axes and the data and feed it to the plot render function.\n  let pl = plot(data: classes, axes: (x_axis, y_axis))\n  histogram(pl, (100%, 40%), stroke: black, fill: (purple, blue, red, green, yellow))\n\n  // Plot 2:\n  // Create the different classes\n  let classes = ()\n  classes.push(class(11, 13))\n  classes.push(class(13, 15))\n  classes.push(class(1, 6))\n  classes.push(class(6, 11))\n  classes.push(class(15, 30))\n\n  // Define the data to map\n  let data = ((20, 2), (30, 7), (16, 12), (40, 13), (5, 17))\n\n  // Create the axes\n  let x_axis = axis(min: 0, max: 31, step: 1, location: \"bottom\", show_markings: false)\n  let y_axis = axis(min: 0, max: 41, step: 5, location: \"left\", helper_lines: true)\n\n  // Classify the data\n  classes = classify(data, classes)\n\n  // Combine the axes and the data and feed it to the plot render function.\n  let pl = plot(axes: (x_axis, y_axis), data: classes)\n  histogram(pl, (100%, 40%))\n```\n\n\n\n![histogram](./images/histogram.png)\n\n### Bar charts\n\n```js\n  // Plot 1:\n  // The data to be displayed\n  let data = ((10, \"Monday\"), (5, \"Tuesday\"), (15, \"Wednesday\"), (9, \"Thursday\"), (11, \"Friday\"))\n\n  // Create the necessary axes\n  let y_axis = axis(values: (\"\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\"), location: \"left\", show_markings: true)\n  let x_axis = axis(min: 0, max: 20, step: 2, location: \"bottom\", helper_lines: true)\n\n  // Combine the axes and the data and feed it to the plot render function.\n  let pl = plot(axes: (x_axis, y_axis), data: data)\n  bar_chart(pl, (100%, 33%), fill: (purple, blue, red, green, yellow), bar_width: 70%, rotated: true)\n\n  // Plot 2:\n  // Same as above, but with numbers as data\n  let data_2 = ((20, 2), (30, 7), (16, 12), (40, 13), (5, 17))\n  let y_axis_2 = axis(min: 0, max: 41, step: 5, location: \"left\", show_markings: true, helper_lines: true)\n  let x_axis_2 = axis(min: 0, max: 21, step: 1, location: \"bottom\")\n  let pl_2 = plot(axes: (x_axis_2, y_axis_2), data: data_2)\n  bar_chart(pl_2, (100%, 60%), bar_width: 100%)\n```\n\n\n\n![bar](./images/bar.png)\n\n### Pie charts\n\n```js\n  show: r =\u003e columns(2, r)\n\n  // create the sample data\n  let data = ((10, \"Male\"), (20, \"Female\"), (15, \"Divers\"), (2, \"Other\")\n\n  // Skip the axis step, as no axes are needed\n\n  // Put the data into a plot\n  let p = plot(data: data)\n\n  // Display the pie_charts in all different display ways\n  pie_chart(p, (100%, 20%), display_style: \"legend-inside-chart\")\n  pie_chart(p, (100%, 20%), display_style: \"hor-chart-legend\")\n  pie_chart(p, (100%, 20%), display_style: \"hor-legend-chart\")\n  pie_chart(p, (100%, 20%), display_style: \"vert-chart-legend\")\n  pie_chart(p, (100%, 20%), display_style: \"vert-legend-chart\")\n```\n\n\n\n![pie](./images/pie.png)\n\n**Overlaid Graphs**\n\n```js\n    // Create the data for the two plots to overlay\n\tlet data_scatter = (\n      (0, 0), (2, 2), (3, 0), (4, 4), (5, 7), (6, 6), (7, 9), (8, 5), (9, 9), (10, 1)\n    )\n    let data_graph = (\n        (0, 3), (1, 5), (2, 1), (3, 7), (4, 3), (5, 5), (6, 7),(7, 4),(11, 6)\n      )\n\n    // Create the axes for the overlay plot\n    let x_axis = axis(min: 0, max: 11, step: 2, location: \"bottom\")\n    let y_axis = axis(min: 0, max: 11, step: 2, location: \"left\", helper_lines: false)\n\n    // create a plot for each individual plot type and save the render call\n    let pl_scatter = plot(data: data_scatter, axes: (x_axis, y_axis))\n    let scatter_display = scatter_plot(pl_scatter, (100%, 25%), stroke: red)\n    let pl_graph = plot(data: data_graph, axes: (x_axis, y_axis))\n    let graph_display = graph_plot(pl_graph, (100%, 25%), stroke: blue)\n\n    // overlay the plots using the overlay function\n    overlay((scatter_display, graph_display), (100%, 25%))\n\n```\n\n\n\n![overlay](./images/overlay.png)\n","funding_links":[],"categories":["Templates \u0026 Libraries"],"sub_categories":["Plotting"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPegacraft%2Ftypst-plotting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPegacraft%2Ftypst-plotting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPegacraft%2Ftypst-plotting/lists"}