Giter Club home page Giter Club logo

inductivecomputerscience / pbplots Goto Github PK

View Code? Open in Web Editor NEW
111.0 7.0 74.0 1.12 MB

A plotting library available in many programming languages.

Home Page: https://repo.progsbase.com/repoviewer/no.inductive.libraries/Plots/latest/

License: MIT License

C 27.10% Shell 0.08% C++ 8.94% Java 10.07% JavaScript 7.52% TypeScript 8.59% C# 7.45% PHP 7.60% Python 7.03% Visual Basic .NET 8.72% Ruby 6.89% Assembly 0.01%
plots graphs easy-to-use reusable

pbplots's Introduction

pbPlots

A plotting library available in many programming languages. Goals of this library are to

  1. Have a single library for plotting that is stable accross programming languages and over time.
  2. Is easy to build in any programming language and to include in any project.
  3. Is easy to use.

The library is developed using progsbase, a technology for writing timeless code. As a consequence, it will be available in many programming languages.

bar plot

atan

regression

Download

Try the Library Online:

General User Guide

The 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.

Basic Usage

Complete example available in the following languages:

Java | C | C++ | JavaScript | TypeScript | PHP | C# | Python | Visual Basic | Ruby

RGBABitmapImageReference imageReference = CreateRGBABitmapImageReference();
StringReference errorMessage = new StringReference();

double [] xs = {-2, -1, 0, 1, 2};
double [] ys = {2, -1, -2, -1, 2};

boolean success = DrawScatterPlot(imageReference, 600, 400, xs, ys, errorMessage);

This code produces the following graph. The boundaries are automatically calculated. The plot is linearly interpolated and drawn in black, one pixel wide.

Example 1

Customization of Plot

Complete example available in the following languages:

Java | C | C++ | JavaScript | TypeScript | PHP | C# | Python | Visual Basic | Ruby

ScatterPlotSeries series = GetDefaultScatterPlotSeriesSettings();
series.xs = new double [] {-2, -1, 0, 1, 2};
series.ys = new double [] {2, -1, -2, -1, 2};
series.linearInterpolation = true;
series.lineType = "dashed".toCharArray();
series.lineThickness = 2d;
series.color = GetGray(0.3);

ScatterPlotSettings settings = GetDefaultScatterPlotSettings();
settings.width = 600;
settings.height = 400;
settings.autoBoundaries = true;
settings.autoPadding = true;
settings.title = "x^2 - 2".toCharArray();
settings.xLabel = "X axis".toCharArray();
settings.yLabel = "Y axis".toCharArray();
settings.scatterPlotSeries = new ScatterPlotSeries [] {series};

RGBABitmapImageReference imageReference = CreateRGBABitmapImageReference();
boolean success;
StringReference errorMessage = new StringReference();
success = DrawScatterPlotFromSettings(imageReference, settings, errorMessage);

This 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.

Example 2

Convert RGBABitmapImage to PNG

Convert to PNG and write to file:

if(success){
  double[] pngdata = ConvertToPNG(imageReference.image);
  WriteToFile(pngdata, "plot.png");
  DeleteImage(imageReference.image);
}

Line Patterns

1: "dotted", 2: "dashed", 3: "dotdash", 4: "longdash", "solid" (not shown) Line Types

Points

1: "triangles", 2: "dots", 3: "crosses", 4: "circles", 5: "filled triangles" (see blow), 6: "pixels" (see blow) Point Types 1 Point Types 2

Colors

  • CreateRGBColor(red, green, blue) - where red, green, blue are the percentages (0-1) of red, green and blue.
  • CreateRGBAColor(red, green, blue, alpha) - where alpha is the percentage of opaqueness (0-1).

Configuration Options

ScatterPlotSettings

  • width - RGBABitmapImage - The width in pixels of the image with the plot.
  • height - RGBABitmapImage - The height in pixels of the image with the plot.
  • title - String - The title on the top of the plot.
  • yLabel, xLabel - String - The labels for the y and x axis, respectively.
  • scatterPlotSeries - (See below) - The series to plot.
  • autoBoundaries - boolean - If on, automatically calculate the boundaries of the plot.
  • xMax, xMin, yMax, yMin - If autoBoundaries are off, these specify the boundaries of the plot.
  • autoPadding - If on, automatically calculate the padding.
  • xPadding, yPadding - Number of pixels - If autoPadding is off, use these paddings.
  • showGrid - boolean - If on, show the grid.
  • gridColor - RGBA - Color of the grid, if shown.

ScatterPlotSeries

  • linearInterpolation - boolean - Whether to use linear interpolation to draw the plot.
  • pointType - String - If linearInterpolation is off, the type of point. Alternatives: "crosses", "circles", "dots", "triangles", "filled triangles", "pixels"
  • lineType - String - "solid", "dotted", "dashed", "dotdash", "longdash"
  • lineThickness - Number of pixels - Thickness of line in pixels.
  • xs, ys - Array of numbers - The x and y coordinates of points in plot.
  • color - RGBA - Color of the points or line.

Multiple Plots in Same Image

RGBABitmapImageReference canvasReference1 = CreateRGBABitmapImageReference();
RGBABitmapImageReference canvasReference2 = CreateRGBABitmapImageReference();
RGBABitmapImageReference canvasReference3 = CreateRGBABitmapImageReference();
RGBABitmapImageReference canvasReference4 = CreateRGBABitmapImageReference();
RGBABitmapImage combined = CreateImage(250*2, 200*2, GetWhite());
RGBABitmapImage image1, image2, image3, image4;

double [] xs = {-2, -1, 0, 1, 2};

double [] ys1 = {2, -1, -2, -1, 2};
double [] ys2 = {-2, 1, 2, 1, -2};
double [] ys3 = {0, 1, 2, 3, 4};
double [] ys4 = {0, -1, -2, -3, -4};

boolean success;
success = DrawScatterPlot(canvasReference1, 250, 200, xs, ys1);
success = success && DrawScatterPlot(canvasReference2, 250, 200, xs, ys2);
success = success && DrawScatterPlot(canvasReference3, 250, 200, xs, ys3);
success = success && DrawScatterPlot(canvasReference4, 250, 200, xs, ys4);

if(success){
  image1 = canvasReference1.image;
  image2 = canvasReference2.image;
  image3 = canvasReference3.image;
  image4 = canvasReference4.image;

  DrawImageOnImage(combined, image1, 0, 0);
  DrawImageOnImage(combined, image2, 0, 200);
  DrawImageOnImage(combined, image3, 250, 0);
  DrawImageOnImage(combined, image4, 250, 200);
}

Multiple Plots on Same Image

Mapping from Plot Coordinates to Pixel Coordinates.

This 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.

xPixels = MapXCoordinateAutoSettings(xPlot, image, xs);
yPixels = MapYCoordinateAutoSettings(yPlot, image, ys);

When using 'DrawScatterPlotFromSettings' use 'MapXCoordinateBasedOnSettings' and 'MapYCoordinateBasedOnSettings' instead, as it will take into account all settings when mapping the coordinate.

xPixels = MapXCoordinateBasedOnSettings(xPlot, settings);
yPixels = MapYCoordinateBasedOnSettings(yPlot, settings);

Custom Drawing on the Plot

The 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.

RGBABitmapImageReference canvasReference = CreateRGBABitmapImageReference();

double [] xs = {-2, -1, 0, 1, 2};
double [] ys = {-2, 1, 2, 1, -2};

boolean success;
StringReference errorMessage = new StringReference();
success = DrawScatterPlot(canvasReference, 600, 400, xs, ys, errorMessage);

if(success){
  double x1 = MapXCoordinateAutoSettings(0, canvasReference.image, xs);
  double y1 = MapYCoordinateAutoSettings(0, canvasReference.image, ys);

  double x2 = MapXCoordinateAutoSettings(1, canvasReference.image, xs);
  double y2 = MapYCoordinateAutoSettings(1, canvasReference.image, ys);

  DrawLine(canvasReference.image, x1, y1, x2, y2, 2, GetGray(0.3));
}

This will produce the following plot.

Custom drawing on plot

Other custom drawing tools available:

  • DrawLine - Draws a line from point (x1, y1) to (x2, y2).
  • DrawPixel - Draws a pixel on point (x, y).
  • DrawRectangle1px, DrawFilledRectangle - Draws a rectangle with upper-left corner at (x, y) with a width w and heigh h.
  • DrawCircle, DrawFilledCircle - Draws a circle with center (x, y) and radius r.
  • DrawTriangle, DrawFilledTriangle - Draws an equilateral triangle with center (x, y) and distance from center to the corners h.
  • DrawText - Draws text with the upper-left point at (x, y).
  • DrawTextUpwards - Draws text upwards with the upper-left point at (x, y).
  • DrawQuadraticBezierCurve - Draws a quadratic Bézier curve from (x0, y0) to (x1, y1) with control point (cx, cy).
  • DrawCubicBezierCurve - Draws a cubic Bézier curve from (x0, y0) to (x1, y1) with control points (c0x, c0y) and (c1x, c1y).

pbplots's People

Contributors

martinfjohansen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pbplots's Issues

X and Y Labels flipped

I had to triple check. And it's late so I may still be wrong.

But it seems the x and y labels are flipped.

Here is a screenshot of a graph with the symptoms:
Flipped Axis

Here is a screenshot of the relevant graphing code snippet:
Code Snippet

And just in case here is code with a single datapoint output:
Data Point
So we know that radii are the larger numbers and are stored in vector radiusses (which I used for graphing x).

Also, great work, and thanks for making it opensource. I'm glad to see a multi-lingual graphing solution. I also appreciate the autoscaling and nan-ignoring it seems to do.

Overlapping Graphs

It would be nice to include a method where multiple graphs using different data can be included on a single png ie multiple lines displaying different data,
An additional change would be allowing users to have both linear interpolation and the Points for easier viewing.

Vector was not declared in this scope

Hi,

I followed this tutorial in order to be able to plot data in my c++ project. I am using QtCreator and my project is a catkin package (i.e. is defined by CMakeLists.txt and package.xml files).

When compiling this simple code of the tutorial I get

‘vector’ was not declared in this scope
     vector<double> x{-2, -1, 0, 1, 2};
     ^~~~~~`

After replacing vector with std::vector my code compiles, but there is no .png file generated.

Do you have any idea what may be the problem?

Thanks

Substandard C

This seems like a useful library. I am a C coder/user. C in here is unfortunately in need of some improvements. Few examples.

What is the point of double as an argument to malloc, for example

// pbPlots.c line 127
colors = (RGBA**)malloc(sizeof(RGBA) * 8.0);

That of course produces a lot of warnings

1>~\pbPlots-0.1.7.1\C\pbPlots.c(127,45): warning C4244: 'function': conversion from 'double' to 'size_t', possible loss of data
  1. standard C is C11.
  2. these days one does
// this is VMT not VLA
colors =  malloc( sizeof( RGBA[8] ) );

Next. There is even code like this one:

// line 151
reference->image->x = (RGBABitmap**)malloc(sizeof(RGBABitmap) * 0.0);
// same as
reference->image->x = NULL ;
// or is it? it depends on the implementation

Next. This code is all heap-based. Stack-based code tends to be faster. But that requires refactoring.
There are dozens of unnecessary heap allocations. As an example CreateRectangle (line:168) is much faster in this form:

// C struct copy elision is very fast, return by value when making struct instances
Rectangle reateRectangle(double x1, double y1, double x2, double y2){
  Rectangle r = {  .x1 = x1, y1 = y1, .x2 = x2, .y2 = y2 } ;
  return r;
}

Also in standard C, there is no need to cast the allocation results. There are much more opportunities for improvement.

I assume all is known and this code will be improved.

could not make the bargraph with x-axis labels work, c++

#include "pbPlots.hpp"
#include "supportLib.hpp"

//library from pbplots, https://github.com/InductiveComputerScience/pbPlots

using namespace std;

int main(){
bool success;
StringReference *errorMessage = CreateStringReferenceLengthValue(0, L' ');
RGBABitmapImageReference *imageReference = CreateRGBABitmapImageReference();

vector<double> ys{2, -1, -2, -1, 2};

BarPlotSeries *series = GetDefaultBarPlotSeriesSettings();
series->ys = &ys;


BarPlotSettings *settings = GetDefaultBarPlotSettings();
settings->width = 800;
settings->height = 600;
settings->title = toVector(L"something");
settings->yLabel = toVector(L"Price");
settings->barPlotSeries->push_back(series);

settings->autoLabels = false;
settings->xLabels = new vector (5.0);
settings->xLabels->at(0) = CreateStringReference(toVector(L"product1"));
settings->xLabels->at(1) = CreateStringReference(toVector(L"product2"));
settings->xLabels->at(2) = CreateStringReference(toVector(L"product3"));
settings->xLabels->at(3) = CreateStringReference(toVector(L"product4"));
settings->xLabels->at(4) = CreateStringReference(toVector(L"product5"));

/*
*/

success = DrawBarPlotFromSettings(imageReference, settings, errorMessage);

if(success){
	vector<double> *pngdata = ConvertToPNG(imageReference->image);
	WriteToFile(pngdata, "example3.png");
	DeleteImage(imageReference->image);
}else{
	cerr << "Error: ";
	for(wchar_t c : *errorMessage->string){
		wcerr << c;
	}
	cerr << endl;
}

FreeAllocations();

return success ? 0 : 1;

}

ive copied the examples and the bargraph without x axis labels work, but when i copied the code for it it doesnt run.
i used replit .

error:
sh -c make -s
./main.cpp:26:27: error: use of class template 'vector' requires template arguments
settings->xLabels = new vector (5.0);
^
/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/include/c++/10.3.0/bits/stl_vector.h:389:11: note: template is declared here
class vector : protected _Vector_base<_Tp, _Alloc>
^
1 error generated.
make: *** [Makefile:10: main] Error 1
exit status 2

Corrupted .png file

Hello, I have recently been working on a simple SIR Epidemic Simulation, and wanted to use pbPlots to visualize the data. Unfortunately, I can't get it to work correctly. Every time I run my code and go to open the png file, it just says that the file is unreadable or corrupted. I also noticed that the file size is only 65 bytes, which is smaller than the usual 180KB.

Here's my code:

/*
	Brandon Pyle
	SIR Epidemic Simulation

	This program is a simple customizable epidemic simulation that uses the SIR model
*/

//Include statements
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "pbPlots.hpp"
#include "supportLib.hpp"

using namespace std;

//Function prototypes

int main()
{
	//The following block of code creates the title box in the command line
	for (int i = 0; i < 50; i++)
		cout << "*";
	cout << endl << setw(49) << left << "*" << right << "*" << endl;
	cout << "*                  Brandon Pyle                  *" << endl;
	cout << "*            SIR Epidemic Simulation             *";
	cout << endl << setw(49) << left << "*" << right << "*" << endl;
	for (int i = 0; i < 50; i++)
		cout << "*";

	cout << endl << endl;

	//Variable Declarations
	int numDays;
	int population;
	double infectionRate = 0.0002; //Percent of other people a person can infect
	double recoveryRate = 10; //In days

	cout << "Enter the length of the simulation in days: ";
	cin >> numDays;

	cout << endl << "Enter the population number for the simulation: ";
	cin >> population;

	if (population > 5000)
		cout << "WARNING: Numbers greater than 5000 may result in incorrect or inaccurate results." << endl;
	else
		cout << endl;

	vector<double> S(population, 0.0); //Number of Susceptible People
	vector<double> I(population, 0.0); //Number of Infected People
	vector<double> R(population, 0.0); //Number of Removed People

	vector<double> xPos;
	for (double i = 0.0; i < numDays; i++)
		xPos.push_back(i);

	I[0] = 1; //Starts the simulation with 6 infected people
	S[0] = population - I[0]; //Initial number of susceptible people
	R[0] = 0; //Initial number of removed people

	RGBABitmapImageReference* imageReference = CreateRGBABitmapImageReference();

	cout << setw(5) << right << "Day";
	cout << setw(13) << right << "Susceptible";
	cout << setw(10) << right << "Infected";
	cout << setw(9) << right << "Removed" << endl;

	for (int i = 0; i < numDays; i++)
	{
		cout << setw(5) << right << i + 1;
		cout << setw(13) << right << fixed << setprecision(0) << S[i];
		cout << setw(10) << right << fixed << setprecision(0) << I[i];
		cout << setw(9) << right << fixed << setprecision(0) << R[i] << endl << endl;

		S[i + 1] = S[i] - infectionRate * S[i] * I[i];
		I[i + 1] = I[i] + infectionRate * S[i] * I[i] - I[i] / recoveryRate;
		R[i + 1] = R[i] + I[i] / recoveryRate;
	}

	ScatterPlotSeries* series = GetDefaultScatterPlotSeriesSettings();
	series->xs = &xPos;
	series->ys = &S;
	series->linearInterpolation = false;
	series->lineType = toVector(L"solid");
	series->color = CreateRGBColor(0, 0, 1);
	
	ScatterPlotSeries* series2 = GetDefaultScatterPlotSeriesSettings();
	series->xs = &xPos;
	series->ys = &I;
	series->linearInterpolation = false;
	series->lineType = toVector(L"solid");
	series->color = CreateRGBColor(0, 1, 0);

	ScatterPlotSeries* series3 = GetDefaultScatterPlotSeriesSettings();
	series->xs = &xPos;
	series->ys = &R;
	series->linearInterpolation = false;
	series->lineType = toVector(L"solid");
	series->color = CreateRGBColor(0, 0, 0);

	ScatterPlotSettings *settings = GetDefaultScatterPlotSettings();
	settings->width = 800;
	settings->height = 480;
	settings->autoBoundaries = true;
	settings->autoPadding = true;
	settings->title = toVector(L"SIR Epidemic Simulation");
	settings->xLabel = toVector(L"Days");
	settings->yLabel = toVector(L"Population");
	settings->scatterPlotSeries->push_back(series);
	settings->scatterPlotSeries->push_back(series2);
	settings->scatterPlotSeries->push_back(series3);

	DrawScatterPlotFromSettings(imageReference, settings);

	//DrawScatterPlot(imageReference, 800, 480, &I, &S);
	
	vector<double>* pngData = ConvertToPNG(imageReference->image);
	WriteToFile(pngData, "SIR_Graph_Test.png");
	DeleteImage(imageReference->image);

	return 0;
}

I have narrowed down the issue to be something with the xPos vector, but I can't figure out why it isn't working. Also, the program does work if you comment out all of the ScatterPlotSeries stuff and uncomment the DrawScatterPlot(...); line. This method works because it uses the I vector for the X axis instead of my xPos vector.

Any suggestions?

C++ example, FreeAllocations()

I am not sure if I should put this here or not, but I am not finding any info when google searching nor can I find the mehtod located anywhere in the files the insturctions have you download when setting up pbPlots so I am curious how to use or where to I find the FreeAllocations() method that is being called in the examples? Thanks for any help with this and my apologizes that it is probably not a real issue just a question I am trying to find an answer to.

Great work on this library by the way, I find it very useful.

rectangle conflict with std::rectangle

I'm using vs2019 and had issue with pbPlots.cpp/.hpp. They are using namespace std and vs used rectangle from wingdi.h instead of local rectangle.
Solved by changing rectangle on rectangle_pbPlots in all files.

Issue with the plotting

The library is working correctly however how to insert a border, grid-on/off and auto marker? Can you please include documentation with respect to C++.

Works Fine but !!

I can draw graph thanks to your libraries but when i try to import the png into my program it misses the bottom part of it :
image
image

What i find strange its the fact that when i close my app it finish to generate the png :
image

How to plot vector of all zeros?

When I try to plot vector of all zeros it shows the following error
It also shows same error for any other value than 0.
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() Aborted (core dumped)

Here's the code

#include "pbPlots/supportLib.hpp"
#include "pbPlots/pbPlots.hpp"

using namespace std;

vector<double> get_p_axis(double step_size){
	int length = 1/step_size + 1.0;
	vector<double> p(length);

	int start = 0;
	for(int i = 0; i<length;i++)
		p[start++] = step_size*i;

	return p;
}

int main(){
	vector <double> p,H_of_p;
	p = get_p_axis(0.001);
	H_of_p.resize(p.size(),0);

	ScatterPlotSeries *series = GetDefaultScatterPlotSeriesSettings();
	series->xs = &p;
	series->ys = &H_of_p;
	series->linearInterpolation = true;
	series->lineType = toVector(L"dashed");
	series->lineThickness = 2;
	series->color = GetGray(0.3);


	ScatterPlotSettings *settings = GetDefaultScatterPlotSettings();
	settings->width = 600;
	settings->height = 400;
	settings->autoBoundaries = true;
	settings->autoPadding = true;
	settings->title = toVector(L"Cross Entropy");
	settings->xLabel = toVector(L"q");
	settings->yLabel = toVector(L"H(q)");
	settings->scatterPlotSeries->push_back(series);

	RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();
	DrawScatterPlotFromSettings(imageRef,settings);
	
	vector<double> *png_data = ConvertToPNG(imageRef->image);
	WriteToFile(png_data,"Assn1_B.png");
	DeleteImage(imageRef->image);

	return 0;	
}```

graph a function in C.

Hello, I am a student and I have a little problem, in my school we need to graph a function and I want to know I can Draw the graph without a line. For example I have this graph and have two lines one of these is the line that I draw and i dont want the other line
Grafica de la forma y=mx+b

problem compiling Example 1 using Visual Studio 2010

I am a relatively new C programmer and am trying to run the pbPlots example 1 under the old (and free) Visual Studio 2010 C IDE. If I am interpretting the error messages correctly, it appears that pbPlots' source file "supportlib.c" makes use of the "FILE" type in a manner incompatible with how its defined in VS2010's header file "stdio.h". I am trying to include a screen grab (with the offending complaint highlighted in yellow) along with this Issue here but I'm not sure I attached it herein correctly... we'll see.

Bottom line, I have no idea whatsoever as to how to even approach this hiccup. Thoughts/suggestions?

tmp 20230509-192513

The "Expression:transposed pointer range" error by using it in C++20

My code:

RGBABitmapImageReference *imageReference = CreateRGBABitmapImageReference();
    vector<double> xs = vector<double>();
    for(int i = 1; i<turn;i++){
        xs.push_back(i);
    }
    vector<double> ys = vector<double>();
    for(int a : s.totalpopulation)
        ys.push_back(a);
    DrawScatterPlot(imageReference, 600, 400, &xs,
                    &ys);

    vector<double> *pngdata = ConvertToPNG(imageReference->image);
    WriteToFile(pngdata, "example1.png");
    DeleteImage(imageReference->image);

The s.totalpopulation is in vector<int>

The exception:
image

How can i fix this, thanks.

Env:
win10 x64
MSVC
I add the cpp file into my cmake file

Are legends supported?

Hi guys, I'm trying the c++ version, I was wondering if legends are supported. I can't find any reference in the source code, so I think that they are not supported.

Vector too long

In some unknown conditions PNum variable inside ComputeGridLinePositions() is getting value NaN, which causes exception Vector too long. Its appearing randomly.

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)

Hello,

I am using pbplots as per the tutorial:
https://github.com/InductiveComputerScience/pbPlots/blob/master/Cpp/example1.cpp
For this new version.

The first error I get is :

error: ‘FreeAllocations’ was not declared in this scope
     FreeAllocations();

If I comment it out, I get the error:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

This is my CMake file:

cmake_minimum_required(VERSION 3.0.2)
project(Canoo)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

#SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
#SET( CMAKE_MODULE_PATH "$ENV{EIGEN3_DIR}" )

find_package(Eigen3 REQUIRED )

link_directories(${Eigen_INCLUDE_DIRS})

# include_directories is needed for the compiler to know where looking for Eigen3 header files to be included 
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/pbplots" )

add_executable(solution main.cpp pbplots/pbPlots.cpp pbplots/supportLib.cpp)

#target_link_libraries(solution eigen)

I kept all the pbplots cpp and hpp in pbplots folder in my current directory. I have no trouble in completion. But execution is trouble.

Whats the problem? though I am following exactly in the tutorial.

ScatterPlot Series color issue

When using color in scatterplot series half the image gets covered by grey coincidentally where the data points start.
as shown in the below example, The language used is C
image

Issue with the png file

Hello,

My code compiles perfectly but no png file is created.
Here the method supposed to plot the curve :

`void Sol::draw_sol_init(){
bool sucess;
StringReference *errorMessage = new StringReference();
RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();
// m_space, m_sol_init are two vector with the same size
sucess = DrawScatterPlot(imageRef, 600, 400, &m_space, &m_sol_init, errorMessage);

if(sucess){
    std::vector<double> *pngdata = ConvertToPNG((*imageRef).image);
    WriteToFile(pngdata, "sol_init.png");
    DeleteImage((*imageRef).image);
    std::cout << "test"  <<std::endl;
}
else{
    std::cout << "nsm" << std::endl;
}

}`

and here my all project
Mesh.zip

Thank you in advance for your help.

std::out_of_range: DrawScatterPlot

#include "pbPlots.hpp"
#include "supportLib.hpp"

using namespace std;

int main(){
bool success;
StringReference *errorMessage = new StringReference();
RGBABitmapImageReference *imageReference = CreateRGBABitmapImageReference();

vector<double> xs{-2, -1, 0, 1, 2};
vector<double> ys{2, -1, -2, -1, 2};
cout<<"only here";
success = DrawScatterPlot(imageReference, 600, 400, &xs, &ys, errorMessage);
cout<<"only here";
if(success){
    vector<double> *pngdata = ConvertToPNG(imageReference->image);
  cout<< "Working here";
    WriteToFile(pngdata, "example1.png");
    DeleteImage(imageReference->image);
}else{
    cerr << "Error: ";
    for(wchar_t c : *errorMessage->string){
        wcerr << c;
    }
    cerr << endl;
}

return success ? 0 : 1;

}

ERROR: terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4294967295) >= this->size() (which is 36)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.