{"id":22940782,"url":"https://github.com/inductivecomputerscience/pbplots","last_synced_at":"2025-08-12T21:31:28.145Z","repository":{"id":48623912,"uuid":"255656180","full_name":"InductiveComputerScience/pbPlots","owner":"InductiveComputerScience","description":"A plotting library available in many programming languages.","archived":false,"fork":false,"pushed_at":"2024-05-05T12:51:41.000Z","size":1146,"stargazers_count":110,"open_issues_count":2,"forks_count":74,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-05T13:48:17.264Z","etag":null,"topics":["easy-to-use","graphs","plots","reusable"],"latest_commit_sha":null,"homepage":"https://repo.progsbase.com/repoviewer/no.inductive.libraries/Plots/latest/","language":"C","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/InductiveComputerScience.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-14T16:01:24.000Z","updated_at":"2024-05-05T12:51:44.000Z","dependencies_parsed_at":"2024-04-21T14:56:14.951Z","dependency_job_id":"2a83a5d7-22aa-429a-aa26-de56b274fd56","html_url":"https://github.com/InductiveComputerScience/pbPlots","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2FpbPlots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2FpbPlots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2FpbPlots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2FpbPlots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InductiveComputerScience","download_url":"https://codeload.github.com/InductiveComputerScience/pbPlots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229708208,"owners_count":18111234,"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":["easy-to-use","graphs","plots","reusable"],"created_at":"2024-12-14T13:31:06.158Z","updated_at":"2024-12-14T13:31:06.628Z","avatar_url":"https://github.com/InductiveComputerScience.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pbPlots\nA plotting library available in many programming languages. Goals of this library are to \n\n1) Have a single library for plotting that is stable accross programming languages and over time.\n2) Is easy to build in any programming language and to include in any project.\n3) Is easy to use.\n\nThe library is developed using [progsbase](https://www.progsbase.com), a technology for writing timeless code. As a consequence, it will be available in many programming languages.\n\n![bar plot](barplot.png \"Bar Plot Example\")\n\n![atan](atan.png \"Arc Tangens\")\n\n![regression](regression.png \"Regression Example\")\n\n## Download\n\n * [Java - 5+](Java/pbPlots/)\n * [C - 99+](C/) | [Video Tutorial](https://www.youtube.com/watch?v=I_xFjVfmRWE)\n * [C++ - 98+](Cpp/) | [Video Tutorial](https://www.youtube.com/watch?v=RNKVHQzvaRM)\n * [JavaScript - 5+](JavaScript/)\n * [TypeScript](TypeScript/)\n * [PHP - 5+](PHP/)\n * [C# - 6+](CS/)\n * [Python - 2+](Python/)\n * [Visual Basic - 9+](VisualBasic/)\n * [Ruby - 2+](Ruby/)\n \n ## Try the Library Online:\n * [Scatter Plot](https://repo.progsbase.com/repoviewer/no.inductive.libraries/Plots/0.1.8///DrawScatterPlotFromSettings/online/)\n * [Bar Plot](https://repo.progsbase.com/repoviewer/no.inductive.libraries/Plots/0.1.8///DrawBarPlotFromSettings/online/)\n\n## General User Guide\nThe library has the same interface in all supported languages. The example below is in Java with links to complete examples in all supported programming languages.\n\n#### Basic Usage\n\nComplete example available in the following languages:\n\n[Java](Java/pbPlots/Example1.java) | \n[C](C/example1.c) | \n[C++](Cpp/example1.cpp) | \n[JavaScript](JavaScript/example1.js) | \n[TypeScript](TypeScript/example1.ts) | \n[PHP](PHP/example1.php) | \n[C#](CS/Example1.cs) | \n[Python](Python/example1.py) | \n[Visual Basic](VisualBasic/example1.vb) |\n[Ruby](Ruby/example1.rb)\n\n```\nRGBABitmapImageReference imageReference = CreateRGBABitmapImageReference();\nStringReference errorMessage = new StringReference();\n\ndouble [] xs = {-2, -1, 0, 1, 2};\ndouble [] ys = {2, -1, -2, -1, 2};\n\nboolean success = DrawScatterPlot(imageReference, 600, 400, xs, ys, errorMessage);\n```\n\nThis code produces the following graph. The boundaries are automatically calculated. The plot is linearly interpolated and drawn in black, one pixel wide.\n\n![Example 1](example1.png \"Example 1\")\n\n#### Customization of Plot\n\nComplete example available in the following languages:\n\n[Java](Java/pbPlots/Example2.java) | \n[C](C/example2.c) | \n[C++](Cpp/example2.cpp) | \n[JavaScript](JavaScript/example2.js) | \n[TypeScript](TypeScript/example2.ts) | \n[PHP](PHP/example2.php) | \n[C#](CS/Example2.cs) | \n[Python](Python/example2.py) | \n[Visual Basic](VisualBasic/example2.vb) |\n[Ruby](Ruby/example2.rb)\n\n```\nScatterPlotSeries series = GetDefaultScatterPlotSeriesSettings();\nseries.xs = new double [] {-2, -1, 0, 1, 2};\nseries.ys = new double [] {2, -1, -2, -1, 2};\nseries.linearInterpolation = true;\nseries.lineType = \"dashed\".toCharArray();\nseries.lineThickness = 2d;\nseries.color = GetGray(0.3);\n\nScatterPlotSettings settings = GetDefaultScatterPlotSettings();\nsettings.width = 600;\nsettings.height = 400;\nsettings.autoBoundaries = true;\nsettings.autoPadding = true;\nsettings.title = \"x^2 - 2\".toCharArray();\nsettings.xLabel = \"X axis\".toCharArray();\nsettings.yLabel = \"Y axis\".toCharArray();\nsettings.scatterPlotSeries = new ScatterPlotSeries [] {series};\n\nRGBABitmapImageReference imageReference = CreateRGBABitmapImageReference();\nboolean success;\nStringReference errorMessage = new StringReference();\nsuccess = DrawScatterPlotFromSettings(imageReference, settings, errorMessage);\n```\n\nThis code produces the following plot. In this plot the line is changed to dashed, 2 pixels wide, light gray. A title has been added and labels for each axis.\n\n![Example 2](example2.png \"Example 2\")\n\n#### Convert RGBABitmapImage to PNG\n\nConvert to PNG and write to file:\n\n```\nif(success){\n  double[] pngdata = ConvertToPNG(imageReference.image);\n  WriteToFile(pngdata, \"plot.png\");\n  DeleteImage(imageReference.image);\n}\n```\n\n#### Line Patterns\n1: \"dotted\", 2: \"dashed\", 3: \"dotdash\", 4: \"longdash\", \"solid\" (not shown)\n![Line Types](linetypes.png \"Line Types\")\n\n#### Points\n1: \"triangles\", 2: \"dots\", 3: \"crosses\", 4: \"circles\", 5: \"filled triangles\" (see blow), 6: \"pixels\" (see blow)\n![Point Types 1](pointtypes1.png \"Point Types 1\")\n![Point Types 2](pointtypes2.png \"Point Types 2\")\n\n#### Colors\n * CreateRGBColor(red, green, blue) - where red, green, blue are the percentages (0-1) of red, green and blue.\n * CreateRGBAColor(red, green, blue, alpha) - where alpha is the percentage of opaqueness (0-1).\n\n#### Configuration Options\n\nScatterPlotSettings\n * **width** - RGBABitmapImage - The width in pixels of the image with the plot.\n * **height** - RGBABitmapImage - The height in pixels of the image with the plot.\n * **title** - String - The title on the top of the plot.\n * **yLabel**, **xLabel** - String - The labels for the y and x axis, respectively.\n * **scatterPlotSeries** - (See below) - The series to plot.\n * **autoBoundaries** - boolean - If on, automatically calculate the boundaries of the plot.\n * **xMax**, **xMin**, **yMax**, **yMin** - If autoBoundaries are off, these specify the boundaries of the plot.\n * **autoPadding** - If on, automatically calculate the padding.\n * **xPadding**, **yPadding** - Number of pixels - If autoPadding is off, use these paddings.\n * **showGrid** - boolean - If on, show the grid.\n * **gridColor** - RGBA - Color of the grid, if shown.\n\nScatterPlotSeries\n\n * **linearInterpolation** - boolean - Whether to use linear interpolation to draw the plot.\n * **pointType** - String - If linearInterpolation is off, the type of point. Alternatives: \"crosses\", \"circles\", \"dots\", \"triangles\", \"filled triangles\", \"pixels\"\n * **lineType** - String - \"solid\", \"dotted\", \"dashed\", \"dotdash\", \"longdash\"\n * **lineThickness** - Number of pixels - Thickness of line in pixels.\n * **xs**, **ys** - Array of numbers - The x and y coordinates of points in plot.\n * **color** - RGBA - Color of the points or line.\n\n#### Multiple Plots in Same Image\n\n```\nRGBABitmapImageReference canvasReference1 = CreateRGBABitmapImageReference();\nRGBABitmapImageReference canvasReference2 = CreateRGBABitmapImageReference();\nRGBABitmapImageReference canvasReference3 = CreateRGBABitmapImageReference();\nRGBABitmapImageReference canvasReference4 = CreateRGBABitmapImageReference();\nRGBABitmapImage combined = CreateImage(250*2, 200*2, GetWhite());\nRGBABitmapImage image1, image2, image3, image4;\n\ndouble [] xs = {-2, -1, 0, 1, 2};\n\ndouble [] ys1 = {2, -1, -2, -1, 2};\ndouble [] ys2 = {-2, 1, 2, 1, -2};\ndouble [] ys3 = {0, 1, 2, 3, 4};\ndouble [] ys4 = {0, -1, -2, -3, -4};\n\nboolean success;\nsuccess = DrawScatterPlot(canvasReference1, 250, 200, xs, ys1);\nsuccess = success \u0026\u0026 DrawScatterPlot(canvasReference2, 250, 200, xs, ys2);\nsuccess = success \u0026\u0026 DrawScatterPlot(canvasReference3, 250, 200, xs, ys3);\nsuccess = success \u0026\u0026 DrawScatterPlot(canvasReference4, 250, 200, xs, ys4);\n\nif(success){\n  image1 = canvasReference1.image;\n  image2 = canvasReference2.image;\n  image3 = canvasReference3.image;\n  image4 = canvasReference4.image;\n\n  DrawImageOnImage(combined, image1, 0, 0);\n  DrawImageOnImage(combined, image2, 0, 200);\n  DrawImageOnImage(combined, image3, 250, 0);\n  DrawImageOnImage(combined, image4, 250, 200);\n}\n```\n\n![Multiple Plots on Same Image](multiplot.png \"Multiple Plots on Same Image\")\n\n#### Mapping from Plot Coordinates to Pixel Coordinates.\nThis code maps coordinates in the plot `(x, y)` to pixel coordinates on the image `(xPixels, yPixels)`. This mapping is based on the automatically generated plot settings given an image `image` and an array of numbers `xs` or `ys`.\n\n```\nxPixels = MapXCoordinateAutoSettings(xPlot, image, xs);\nyPixels = MapYCoordinateAutoSettings(yPlot, image, ys);\n```\n\nWhen using 'DrawScatterPlotFromSettings' use 'MapXCoordinateBasedOnSettings' and 'MapYCoordinateBasedOnSettings' instead, as it will take into account all settings when mapping the coordinate.\n\n```\nxPixels = MapXCoordinateBasedOnSettings(xPlot, settings);\nyPixels = MapYCoordinateBasedOnSettings(yPlot, settings);\n```\n\n#### Custom Drawing on the Plot\n\nThe following code draws a line from (0, 0) to (1, 1) in the plot's coordinate system. The coordinates must be mapped to pixel coordinates before drawing. The mapping is based on the automatic settings calculated from the image dimensions and plot data.\n\n```\nRGBABitmapImageReference canvasReference = CreateRGBABitmapImageReference();\n\ndouble [] xs = {-2, -1, 0, 1, 2};\ndouble [] ys = {-2, 1, 2, 1, -2};\n\nboolean success;\nStringReference errorMessage = new StringReference();\nsuccess = DrawScatterPlot(canvasReference, 600, 400, xs, ys, errorMessage);\n\nif(success){\n  double x1 = MapXCoordinateAutoSettings(0, canvasReference.image, xs);\n  double y1 = MapYCoordinateAutoSettings(0, canvasReference.image, ys);\n\n  double x2 = MapXCoordinateAutoSettings(1, canvasReference.image, xs);\n  double y2 = MapYCoordinateAutoSettings(1, canvasReference.image, ys);\n\n  DrawLine(canvasReference.image, x1, y1, x2, y2, 2, GetGray(0.3));\n}\n```\n\nThis will produce the following plot.\n\n![Custom drawing on plot](customdrawing.png \"Custom drawing on plot\")\n\nOther custom drawing tools available:\n\n * **DrawLine** - Draws a line from point `(x1, y1)` to `(x2, y2)`.\n * **DrawPixel** - Draws a pixel on point `(x, y)`.\n * **DrawRectangle1px**, **DrawFilledRectangle** - Draws a rectangle with upper-left corner at `(x, y)` with a width `w` and heigh `h`.\n * **DrawCircle**, **DrawFilledCircle** - Draws a circle with center `(x, y)` and radius `r`.\n * **DrawTriangle**, **DrawFilledTriangle** - Draws an equilateral triangle with center `(x, y)` and distance from center to the corners `h`.\n * **DrawText** - Draws text with the upper-left point at `(x, y)`.\n * **DrawTextUpwards** - Draws text upwards with the upper-left point at `(x, y)`.\n * **DrawQuadraticBezierCurve** - Draws a quadratic Bézier curve from `(x0, y0)` to `(x1, y1)` with control point `(cx, cy)`.\n * **DrawCubicBezierCurve** - Draws a cubic Bézier curve from `(x0, y0)` to `(x1, y1)` with control points `(c0x, c0y)` and `(c1x, c1y)`.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finductivecomputerscience%2Fpbplots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finductivecomputerscience%2Fpbplots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finductivecomputerscience%2Fpbplots/lists"}