JavaPlot - How to plot more data sets to same graphic? - graph

I want to compare time series data in just one graphic. I added several data sets to same plot and plot it - just one data set is shown. Documentation missing, existing questions useless..
Question: Why is just one data set represented? And also, why is its' title not used to create a legend?
My code (sniped):
//first, create terminal to write png files (not shown)
..
//create the three data sets (just shown for first data set here)
double[][] original = combinedSequence.getOriginalValues();
AbstractPlot originalPlot = new DataSetPlot(original);
originalPlot.setTitle("'original'");
..
//add the three data set plots
p.addPlot(originalPlot);
p.addPlot(offsetPlot);
p.addPlot(functionPlot);
//plot graph
p.newGraph();
p.plot();

Two things:
newGraph() should be set before any subplot
titles should not have '
So, a correct version of your code will be:
double[][] original1 = {{2,3},{4,5},{6,7}};
double[][] original2 = {{8,9},{12,13},{14,15}};
AbstractPlot originalPlot = new DataSetPlot(original1);
originalPlot.setTitle("original1");
AbstractPlot originalPlot2 = new DataSetPlot(original2);
originalPlot2.setTitle("original2");
JavaPlot p = new JavaPlot();
p.addPlot(originalPlot);
p.newGraph();
p.addPlot(originalPlot2);
p.plot();

Related

R: How to Write a Function that Creates a Scatterplot of Two Variable Based Upon Value of Specified Third Variable

I am new to R. I am trying to create a function (using Loblolly) that plots the Height and Age based upon a specified Seed number in the data. I don't know how one would go about setting this function up.
Loblolly
lob<-function (z){
z<-Loblolly$Seed
x<-Loblolly$age
y<-Loblolly$height
return(plot(x,y))
}
lob(301)
This is what I am getting:
This is what I would like to bet getting:
Figured it out:
lob<-function (z){
x<-Loblolly$age
y<-Loblolly$height
return(plot(x[Loblolly$Seed == z],y[Loblolly$Seed == z],xlab="Age",ylab="Height"))
}
lob(323)

Combine data from two datasources into a single table

I have two datasets:
Dataset 1 - Records the details of a store visit. Merchandiser name, location, date & a relation to SKU (Dataset 2)
Dataset 2 - This is the SKU data, where the stock levels for each sku are input as a new record, each associated to a visit from Dataset 1.
I have two issues:
I want to combine this data into a single table. I want to show each SKU record, with additional columns for the visit information (such as the location & date). How do I do this.
How do I combine this data for use elsewhere, such as google data studio. Essentially I want to be able to see an SKU's stock-level's history, or the date it was last updated.
You need to create Calculated Data Source. You can refer this sample.
On a high Level
Add data source in Appmaker.
Select Calculated, provide Name and Create the data source.
Once your Calculated Model is in place. Add fields as per need basis. e.g. If you want to store Sum of two fields, create one Integer field in Calculated Model. Here's how your calculated data model will look like.
Now go to Second Tab which is "Datasources". Click on the Data Model name there. You should see an option to write server side script.
Here you should write your logic for combining your data sources. I can provide you one sample to achieve this.
//server script
var calculatedModelRecords = [];
var recordsByStatus = {};
var allRecord = app.models.Request.newQuery().run(); //your existing data source.
for (var i = 0; i < allRecord.length; i++) {
var record = allRecord[i];
var draftRecord = app.models.TAT.newRecord(); //new data source
draftRecord.CreatedOn = record.CreatedOn;
draftRecord.DocumentName = record.DocumentName;
draftRecord.DueDate = record.DueDate;
draftRecord.DaysPerStage = record.DaysPerStage;
draftRecord.Status = record.Status;
calculatedModelRecords.push(draftRecord);
}
return calculatedModelRecords;

Overlay multiple images in python

My problem is that I have bunch of jpgs and I would like to overlay all of them to see a pattern.
I checked out this answer(Overlay two same sized images in Python) but it only shows how two images can be overlayed.
Here are the piece of code which shows I'd like to do.
for file in os.listdir(SAVE_DIR):
img1 = cv2.imread(file)
img2 = cv2.imread('next file name') #provide previous output file here (dst)
dst = cv2.addWeighted(img1,0.5,img2,0.5,0)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
One approach is to store all your images as a list, and then iterate through each overlapping pair of images and callcv2.addWeighted() on each element in your list, passing in the last aggregate image in as img1 to your subsequent call to cv2.addWeighted().
So for example, say you have 4 images, with names [img1, img2, img3, img4].
You could do
jpeg_list = os.listdir(SAVE_DIR)
for i in range(len(jpeg_list)):
aggregate_file = cv2.imread(jpeg_list[i])
next_img = cv2.imread(jpeg_list[i+1])
dst = cv2.addWeighted(aggregate_file, 0.5, next_img, 0.5, 0)
cv2.imshow('dst', dst)

How to create a GenericGraph based on ExVertex and ExEdge with Graphs.jl in julia?

I am a new user of Julia and I want to work on graphs. I found the Graphs.jl library but not very documented. I tried to create a GenericGraph based on ExVertex and ExEdge but I need more information.
The code I'm using :
using Graphs
CompGraph = GenericGraph{ExVertex, ExEdge{ExVertex}}
temp = ExVertex(1, "VertexName")
temp.attributes["Att"] = "Test"
add_vertex!(CompGraph, temp)
Now I still need the ExVertex list and ExEdge list. Is there any defined parameters? or how can I create such lists?
The solution was too simple. a list is juste a simple array and not a new type. Besides, there is a simple defined function which creates graphs based on different types of edges and vertecies.
I changed my code to :
using Graphs
CG_VertexList = ExVertex[]
CG_EdgeList = ExEdge{ExVertex}[]
CompGraph = graph(CG_VertexList, CG_EdgeList)
temp = ExVertex(1, "VertexName")
temp.attributes["Att"] = "Test"
add_vertex!(CompGraph, temp)

Flex Charts: Can you use a minimum/maximum point from an IAxis for Cartesian Data Canvas to draw the entire width of the chart?

I have a chart with a DateTime axis as my horizontal and a Linear Axis for my vertical inside a Adobe Flex Line Chart. I want to use a Cartesian Data Canvas as a background element and draw custom set of background graphics mostly rectangles. When I have more than a single data point, the graphics work perfectly since they are supposed to span the width of the entire chart.
When I have only a single data point, however, I can't seem to get the rectangles to draw. Since I want my rectangles to span the entire width of the chart, I was thinking that I could get the x-coordinates from my axis, but this isn't working.
var canvasWidth:Number = chtCanvas.width;
var canvasHeight:Number = chtCanvas.height;
var minPt:Array;
var maxPt:Array;
var minPtDate:Date;
var maxPtDate:Date;
var minPtComplete:Point;
var maxPtComplete:Point;
// This works fine when there is more than 1 data point
minPt = chtCanvas.localToData(new Point(0, 0));
maxPt = chtCanvas.localToData(new Point(canvasWidth,canvasHeight));
//This does return a date object, but wont draw below
minPtDate = axisDate.minimum;
maxPtDate = axisDate.maximum;
//This returns NaN for the x
minPtComplete = chtCanvas.dataToLocal(minPtDate, axisSalary.minimum);
maxPtComplete = chtCanvas.dataToLocal(maxPtDate, axisSalary.maximum);
// Also tried this. Also returns NaN for the x value
//minPtComplete = chtCanvas.dataToLocal(axisDate.minimum, axisSalary.minumum);
//maxPtComplete = chtCanvas.dataToLocal(axisDate.maximum, axisSalary.maximum);
My actual drawing method is as follows:
// Tried this, works with points >2, does not draw with single data point
chtCanvas.drawRect(minPt[0], detail[i].MaxValue, maxPt[0], detail[i].MinValue);
//tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, detail[i].MaxValue, maxPtDate, detail[i].MinValue);
// Tried this, no effect with single point
//chtCanvas.drawRect(minPtDate, minPt[1], maxPtDate, detail[i].MinValue);
// Tried this also
//chtCanvas.drawRect(minPtComplete.x, detail[i].MaxValue, maxPtComplete.x, detail[i].MinValue);
In this example, detail is an array collection of salary values and Im using the data value in the array to determine the vertical bounds of my rectangles.
I need to draw the rectangles the entire width of the chart (even when there is only a single data point). Thanks
Thanks to Heikki for his help. The following code works to use the axis values to draw on your Cartesian Data Canvas:
chtCanvas.drawRect(axisDate.minimum as Date, axisSalary.maximum, axisDate.maximum as Date, axisSalary.minimum);
Casting the values as Date really helped. The rest of the code used above is unecessary.
One thing to note, I was using a DateFormatter to format the date values from my data. What I didn't consider was that when using a DateTimeAxis, Flex will automatically add in extra dates to display on the axis. In my case, I was using a custom parse function to create MY points, but wasnt considering the points Flex was creating and also passing to my parse function (Therefore, they were not getting parsed correctly). Once I corrected this, the values laid out correctly in the case of multiple data points. I'm still having a bit of an issue with single data points and them not filling the chart entirely, but they are now drawing.
UPDATE:
Although there are signs of life, the minimum and maximum are still not drawing the entire width of the chart in some cases depending on the dataUnits and labelUnits combination.
UPDATE #2: SOLVED
Ok, so the axis does work as minimum/maximum values for the Cartesian Data Canvas but there is something important to remember. For a single point (and probably for multiple points as well, I just couldnt visually see the difference), when using a custom DateTimeAxis parse function such as what was in the Adobe Flex ASDoc tutorials:
private function axisDateParseFunction(item:String):Date
{
var inputDate:String = item;
inputDate = fmtDate.format(inputDate);
var newDate:Date = new Date();
if(inputDate)
{
var a:Array = inputDate.split('/');
newDate.fullYear = a[2];
newDate.month = a[0] - 1;
newDate.date = a[1];
newDate.hours = 0;
newDate.hoursUTC = 0;
newDate.minutes = 0;
newDate.minutesUTC = 0;
newDate.seconds = 0;
newDate.secondsUTC = 0;
newDate.milliseconds = 0;
newDate.millisecondsUTC = 0;
}
return newDate;
}
You MUST remember to set the UTC values as shown above also. Since the DateTimeAxis uses date AND time, when you create new Date objects, their time values also get set to the local system time. Remember to set those values to zero also or you will get points that dont exactly line up with your axis labels.

Resources