jfreechart get current TickUnit value - jfreechart

I have an XYPlot displaying points and lines.
The points are created randomly so the chart will be different every time I launch the application.
With my current example, I've got the following TickUnit :
- Y axis : 1 2 3 4 5 6 ...
- X axis : 0.2 0.4 0.6 0.8 ...
I'm trying to get current TickUnit but it returns "size=1" for both axis :
NumberAxis range1 = (NumberAxis)plot.getRangeAxis();
NumberTickUnit ntu1 = range1.getTickUnit();
System.out.println(""+ range1.getTickUnit().toString());
NumberAxis range2 = (NumberAxis)plot.getDomainAxis();
NumberTickUnit ntu2 = range2.getTickUnit();
System.out.println(""+ range2.getTickUnit().toString());
Any idea how I can get 0.2 for X axis ?
I'd like to get these values so that I can add an annotation over a line at an appropriated distance.

The documentation mentions:
Note: if the autoTickUnitSelection flag is true the tick unit may be changed while the axis is being drawn, so in that case the return value from this method may be irrelevant if the method is called before the axis has been drawn.
Try calling the method after the graph is displayed, e.g. using SwingUtilities.invokeLater().

Related

in MathGL how to get values an array after math operation

I have a code which perfectly draws a sine wave graph
y = mgl_create_data_size(100,1,0);
mgl_data_modify(y,"0.4*y+0.1+sin(6*pi*x)",0);
gr = mgl_create_graph(WINDOW_WIDTH, WINDOW_HEIGHT);
mgl_plot(gr,y,". ","");
mgl_box(gr);
Now that the variable y is a MathGL data type HMDT
How I will get numeric values from it
I see there is function which mgl_data_get_value(y,i,j,0);
but it only accepts long data type and it always returns NaN
I found the answer that, I am trying to assume j as incremental value.
But, base on trial and error based, when I set j as 0 I am getting all the 100 graph values which applied based on the MathGL formula 0.4*y+0.1+sin(6*pi*x).
So the assumption of the function mgl_create_data_size is
If the data is set using 100,1,0 which is nx,ny,nz
nx = 100 - Total number of X axis values
ny = 1 - is only one Y value for each X value
nz = 0 - is assumed as 0, there is no z axis
the function which can get each graph value is
mgl_data_get_value(y,i,0,0)
Example of 10 values for the same formula
var y1 = mgl_create_data_size(10,1,0)
mgl_data_modify(y1,"0.4*y+0.1+sin(6*pi*x)",0)
for(i in 0..10-1) {
println(mgl_data_get_value(y1,i,0,0))
}
The output is
0.1
0.9660254037844387
-0.7660254037844384
0.09999999999999976
0.9660254037844391
-0.7660254037844387
0.09999999999999952
0.9660254037844401
-0.7660254037844377
0.09999999999999927
The graph in Excel for the above values is
This is very help full to use MathGL in applied mathematics in data generation as one of the light weight libraries

How to plot 4d data into heatplot using gnuplot

plz help!
i have a dataset with the format of
x y z p
-0.574142 -0.818671 0.011756 0.000440
-0.364919 0.184603 0.912555 0.000324
-0.990822 -0.022168 0.133345 0.000419
-0.983317 -0.089955 0.158099 0.000417
-0.493497 0.474422 -0.728961 0.000501
-0.789287 -0.566719 0.236336 0.000413
0.293932 0.520691 -0.801551 0.000510
and they are random points on a 3d sphere, with the p value (the fourth column) representing the "heat" of that location, the actual datafile is with 50 such points.
i want to plot the surface of the sphere into a heatplot, not each point being colored.
i've searched for lots of post, all of them would require some kind of isoline, but in my case there isn't any. is it possible still using gnuplot to do heatmap? i'm also opened to any other way.
btw im running linux with newest gnuplot, the data are generated by c
ps: i understand theres a way of making data into isolines and then use gnuplot with pm3d, but i cant do that because all my x data is randomized, hence there is no isoline.
Note: This answer is only relevant to the newest gnuplot, version 5.4
Gnuplot version 5.4 can work in a 3D grid space of voxels, The voxel values can be used to hold a 4th dimension of data. I.e voxel(x,y,z) = value
This is a very new feature and could be improved, so your question serves as a nice example to show what it can and cannot do right now.
$data << EOD
x y z p
-0.574142 -0.818671 0.011756 0.000440
-0.364919 0.184603 0.912555 0.000324
-0.990822 -0.022168 0.133345 0.000419
-0.983317 -0.089955 0.158099 0.000417
-0.493497 0.474422 -0.728961 0.000501
-0.789287 -0.566719 0.236336 0.000413
0.293932 0.520691 -0.801551 0.000510
EOD
#
# Generate a heatmap on the surface of a sphere
#
set view equal xyz
set view 78, 246
set xyplane at 0
unset key
set xtics ("x" 0); set ytics ("y" 0); set ztics ("z" 1)
set hidden3d # only relevant to axis tics and labels
#
# Use spherical mapping to generate a set of points describing the surface.
# Then return to Cartesian coordinates to handle voxels.
#
set mapping spherical
set angle degrees
set samples 51
set isosamples 101
set urange [-90:90]
set vrange [0:360]
set table $surface
splot '++' using 1:2:(1.0) with points
unset table
set mapping cartesian
# define 100 x 100 x 100 voxel grid
rlow = -1.1; rhigh = 1.1
set xrange [rlow:rhigh]; set yrange [rlow:rhigh]; set zrange [rlow:rhigh]
set vgrid $vdensity size 100
vclear $vdensity
# mark voxels in a spherical region with radius <near> around each point in $data
# Note that values are summed rather than averaged
near = 0.1
vfill $data skip 1 using 1:2:3:(near):($4)
show vgrid
# color range should be found automatically but it isn't
set cbtics
set colorbox user origin screen 0.8, screen 0.2
set cbrange [ 0 : 0.001 ]
set palette cubehelix negative # colors from cbmin white -> cbmax dark
set pm3d depthorder
set pm3d lighting primary 0.4 specular 0.1
set title "Sphere surface is colored by the value of the nearest point[s] in $data"
splot $surface using 1:2:3:(voxel($1,$2,$3)) with pm3d

Do we have a way to know the X Axis value of first point in line chart?

There are multiple series in my line chart. Each series contains multiple points. I wonder is there a property I can easily use to get the min/max X Axis value among all of those points for all series? Or whether the chart doesn't support this I have to get the value from my data set?
Thanks
Sample Data:
Series A:
Argument:Value:
A:1
B:2
C:3
Series B:
Argument:Value:
A:2
B:3
C:4
D:5
You can use the following code to get the min and max value.
var dg = (XYDiagram)chartControl1.Diagram;
var minXValue = dg.AxisX.WholeRange.MinValue;
var maxXValue = dg.AxisX.WholeRange.MaxValue;
If you want to only get the min and max values for the visible range. use this
var dg = (XYDiagram)chartControl1.Diagram;
var minXValue = dg.AxisX.VisualRange.MinValue;
var maxXValue = dg.AxisX.VisualRange.MaxValue;
Result base on whole range code above
Min X Value: A
Max X Value: D
Hope this helps

Get every Y value from every line based on a X value

Using OxyPlot library, I have a LineSeries with a max count of 8. Given a X value (got from a left mouse click), how can I get (and show it in the legend) the corresponding Y value for each line?
You can get the point value using the MouseDown method which you attach to your line series found here in the MouseDownEventHitTestResult method
var s1 = new LineSeries();
s1.MouseDown += (s, e) =>
{
model.Subtitle = "Y value of nearest point in LineSeries: " +
Math.Round(e.HitTestResult.NearestHitPoint.Y);
model.InvalidatePlot(false);
};
There doesn't appear to be any way to change much of whats in the legend area as that's just a reflection of the graph titles. You could display it to the subtitle as in the example or draw an annotation on the screen.
They have a whole bunch of examples you can look through for ideas here

JfreeChart Axis custom precision or range

I am trying to plot a XYPlot using JfreeChart. My X axis has number or client say 30, 50 ,70
and Y axis has cache hit ratio( Value of which sometime varies by 0.01) When i set AutoRange the y axis show range as 0.1 0.2 0.3..... 1.0. So sometimes my plot is nearly straight line since it varies by such a small factor.
I have tried this code
JFreeChart chart = ChartFactory.createXYLineChart(
"Effect of Number of Clients", // Title
"Number of Clients", // x-axis Label
"Cache Hit Ratio", // y-axis Label
datasetLRU, // Dataset
PlotOrientation.VERTICAL, // Plot Orientation
true, // Show Legend
true, // Use tooltips
false // Configure chart to generate URLs?
);
chart.setBackgroundPaint(Color.white);
plot= chart.getXYPlot();
plot.setBackgroundPaint(Color.black);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
final ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(false);
final NumberAxis axis2 = new NumberAxis("Axis 2");
axis2.setAutoRangeIncludesZero(false);
axis2.setTickUnit(new NumberTickUnit(0.01));
plot.setDataset(1, datasetMARS);
plot.setRenderer(1, new StandardXYItemRenderer());
plot.setDataset(2, datasetNEW);
plot.setRenderer(2, new StandardXYItemRenderer());
So Can any one help in setting Y axis range as 0.01 0.02 0.03 .... 0.98 0.99 1.00
Thanks
Your code doesn't configure the range axis because you create axis2 but you never assign it. When using auto range you can also configure the minium size of an auto ranged axis (method setAutoRangeMinimumSize(double)).
Please try the following source code part:
final NumberAxis axis2 = plot.getRangeAxis();
axis2.setAutoRange(true);
axis2.setAutoRangeIncludesZero(false);
axis2.setAutoRangeMinimumSize(0.001);
axis2.setTickUnit(new NumberTickUnit(0.01));

Resources