JavaFX2 XYChart axis label and custom grid line - charts

are there methods in javafx2 to override the ticket label X and Y axis so to custom set axis formatter?
2) How to enlarge X or Y axis space in order to get more space for ticket label ?
3) How to set the grid to appear as logarithmic, or redefine dynamically grid line space ?

To enlarge Y axis width you can use
yAxis.setPrefWidth(35);

Related

How to have vertical x labels?

Soft Question: How to edit the x label in a bar graph to be vertical in Matlab?
Here is an example of the x-axis I would like to have
You have to get the handle of the axis first. Then you can edit the X axis Tick rotation property which is zero by default. By setting this parameter to 90, it will rotate your x-axis like your picture.
h = gca; % handle for current axis
h.XTickLabelRotation = 90; % rotate the tick label

Matlab: Replicate legend location's 'outside' scaling behavior

The preceding figure was produced by the following code:
hold on;
plot([1,2,3,4],[1,2,3,4]);
plot([1,2,3,4],[4,3,2,1]);
legend('foo', 'bar', 'location', 'eastoutside');
Re-scaling the width of the figure window causes the legend to maintain it's dimensions, while automatically scaling the plot's width to take up the extent of the remaining space:
When editing the position properties of the legend, the location property is changed to 'none', losing its unique scaling behavior.
Is there any way to reproduce the scaling behavior in such a way that I could resize/re-position the legend and/or use it for a non axis-legend relationship?
You can get the position of the axes and set the position of the legend relative to them. Here is an example:
x = -10:10;
fig = figure(1);
plot(x,x.^2,x,x.^3);
hL = legend('foo','bar');
% setting the position to the bottom right corner of the axes:
ax = gca;
hL.Position(1:2) = [sum(ax.Position([1 3]))-hL.Position(3) ax.Position(2)];
To keep the position updated upon resizing of the figure you can assign the position set to the SizeChangedFcn property of the figure:
fig.SizeChangedFcn = ...
'hL.Position(1:2) = [sum(ax.Position([1 3]))-hL.Position(3) ax.Position(2)];';
any resize of the figure will update the legend position.

JAVAFX CHARTS: Setting origin point on category axis

I am in need to add a zero point for category axis in javafx line chart. In the image I want some "T0" to represent the zero mark of origin on the x axis, so that I can mark point on y axis as on the chart.
sample line chart ( looks like bar chart !)
I'm not completely clear what you're asking, but if you want the pixel coordinates of the left end of the x-axis, you can do
Category xAxis = ... ;
// ...
double leftEnd = xAxis.getDisplayPosition(value0) - xAxis.getCategorySpacing();
where value0 is the x-value of the first data point.

MATLAB: The exact size and position of the axis box in the case of `axis equal`?

How to know the exact size and position of the axis box (without axis labels and numbers)? For example, if I use
figure
contourf(x,y,u,100,'linestyle','none')
axis equal
set(gca,'position',[0.1,0.1,0.7,0.8]) %normalized units
The size of the axis frame/box is varyed in the case of the figure window resizing (or using axis equal), but the value of get(gca,'position') remains unchanged. For example:
figure
Z = peaks(20);
contourf(Z,10)
set(gca,'Units','pixels')
get(gca,'position')
axis equal
get(gca,'position')
ans =
0.1300 0.1100 0.7750 0.8150
after axis equal, the axis box is changed, but get(gca,'position') gives the same coordinates:
ans =
0.1300 0.1100 0.7750 0.8150
I need these to align the colorbar to the axis box (with fixed gap between them) in the case of axis equal.
When you call axis equal, the axis box aspect ratio is fixed and the Position property is treated as a maximum size. When you resize the figure window, the axis box will remain centered in the Position rectangle, but in order to maintain the same aspect ratio as before, it may not take up the entire Position rectangle.
If you want it to take up the entire Position rectangle, you can call axis equal again. (this may depend on your MATLAB version; it worked for me in R2015b).
This is also discussed in a bit more detail on MATLAB Central.
To answer your original question, it's a bit complicated. You'd have to get the plot box aspect ratio (using pbaspect() or the axes PlotBoxAspectRatio property) and figure it out:
ah = gca();
% Get the axes Position rectangle in units of pixels
old_units = get(ah,'Units');
set(ah,'Units','pixels');
pos = get(ah,'Position');
set(ah,'Units',old_units);
% Figure the PlotBox and axes Position aspect ratios
pos_aspectRatio = pos(3) / pos(4);
box_aspect = pbaspect(ah);
box_aspectRatio = box_aspect(1) / box_aspect(2);
if (box_aspectRatio > pos_aspectRatio)
% PlotBox is wider than the Position rectangle
box_height = pos(3) / box_aspectRatio;
box_dy = (pos(4)-box_height) / 2;
box_position = [pos(1), pos(2)+box_dy, pos(3), box_height];
else
% PlotBox is taller than the Position rectangle
box_width = pos(4) * box_aspectRatio;
box_dx = (pos(3)-box_width) / 2;
box_position = [pos(1)+box_dx, pos(2), box_width, pos(4)];
end
Note that this will give you the box position in pixels; if you want it in the normalized units that are the axes default, you'll need to normalize it:
fig_pos = get(get(ah,'Parent'),'Position');
box_position = box_position ./ fig_pos([3 4 3 4]);

How to draw a graph with vertical lines of fixed height at several points

Basically, I want to draw a graph whose x axis varies from -10 to 10, and the y axis varies from 0 to 10. The graph has vertical lines of height 4 at x = -1 and x = 1.
(I guess, it is a bar graph with infinitely thin bars)
You can for example cheat with the stem function
stem([-1 1],[4 4],'Marker','none');