I got a plot for which I defined the Y range as -2000 to 2000
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(1) length:CPTDecimalFromInt(600)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2000) length:CPTDecimalFromInt(2000)];
The plot is fitted to the graph along the X axis, causing the majority of the Y axis to be cut off. How can I ask the core plot to autoscale the Y axis to make the maximum value in a series just touch the top of the screen?
Thank you!
Plot ranges are defined by a location and a length, similar to NSRange. To make a range that spans between -2000 and 2000, your yRange should have a location of -2000 and length 4000.
You can autoscale a plot space using the -scaleToFitPlots: method. Several of the Core Plot example apps use this method to fit plots to their data.
Related
I struggle a little bit with overlapping axis numbers of the y and x axis like it is shown in the image. I'd like to keep the size of the numbers and therefore think that simply shifting the numbers away from the axis itself would be an appropriate way to handle this issue.
Is there a possibility to do that?
Thanks in advance,
Joe
Here is a little workaround using text annotations. Basically you clear the current XTick labels and replace them with similar labels, but you can specify the distance from the axis:
clc
clear
close all
x = 1:20;
hPlot = plot(x,sin(x));
set(gca,'xaxisLocation','top');
set(gca,'XTickLabel',[]); %// Clear current XTickLabel
ylim = get(gca,'YLim'); %// Get y limit of the plot to place your text annotations.
for k = 2:2:20
text(k,ylim(2)+0.1,num2str(k),'HorizontalAlignment','Center') %// Play with the 'ylim(1) -0.1' to place the label as you wish.
end
Giving this:
Of course now it's exaggerated and you can do the same for the y axis if you want (using the 'XLim' property of the current axis,gca).
I am creating scatter graph, I need to change the x and y positions in scatter graph. Graph always starts with (0,0) positions but i need to show the starting points (7000, 800). Is there any way to change the x and y positions in scatter graph in core plot.
After showing the graph need to draw the line manually and get those values to search the properties.
Please help me.
Thanks in advance.
to set the point where the co-ordinates meet you have to set the orthogonal co-ordinate decimal
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"800");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(#"740000");
and for setting the range of values to be plotted set the visibleRange for both the axes
These are features of the "plot space" in Core Plot. It defines the coordinate mapping between the plot area (basically the rectangle that contains all plot drawing) in data coordinates and the view in drawing coordinates. The xRange and yRange control the x and y range of the plot space, respectively.
The plot space converts coordinates in both directions—from data to view when drawing and from view to data when (for example) responding to touch events on a plot. See the plot space docs for a list of the available coordinate conversion methods.
I'm using Core Plot to graph linear equations. I have two data points; the X and Y intercept of the line.
I want to scale the the plot area to fit the plot in view.
I tried using
[plotspace scaleToFitPlots: [NSArray arrayWithObject:mainPlot]];
which worked, except that the axes were scaled independently:
The X axis is stretched relative to the Y axis. So that the slope of the line is shown accurately, it is important that both axes be scaled together.
How can I scale a plot area to fit a plot while maintaining an equal relationship between axes?
To be clear, the range of the axes can vary, but the physical amount of onscreen space between 0 and 1 needs to be the same on both axes.
After calling -scaleToFitPlots:, inspect the resulting plot ranges and adjust them as needed to achieve the effect you want. Compare the length of each range to the corresponding dimension of the plot area bounds (compute the ratio between the length and bounds size), determine if one ratio is larger than the other, and adjust the ranges as needed so the ratios match.
I am implementing core plot framework for graph plot, but I am not able to understand following issues :
How to change the scaling point on XY axis. For example right now by deafault it is showing points on x axis is 1,2,3,4,5....etc and on y axis 1,2,3,4,5,....etc and I want on y axis 100,200,300,400,...etc.
How to set the coordinate of whole graph, means as I run my app the graph is totally downside and not visible and to see the graph I have to drag it upside.
Please help me out ASAP.
Thanks in advance.
You control the visible data using the xRange and yRange of the plot space. See this question for an example.
There are several options for setting up the labels, controlled by the labelingPolicy property. One of the pages in the Plot Gallery example app shows samples of all of the labeling policies. Which one you choose depends on how much you know about the range of data that will be displayed and whether the user can scroll and/or zoom the graph.
1) y_axis.majorIntervalLength = CPTDecimalFromString(100); // for 100 ,200 .....
2)
plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-0.99) length:CPTDecimalFromFloat(7.5)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-4.9) length:CPTDecimalFromFloat(45)];
// you can visible directly graph... or you can set start location as 1st parameter and length as 2nd parameter
I just can't find it. How to set up axis and labels in matlab so they cross at zero point, with the labels just below the axis not on left/bottom of the plot ?
If I didn't make myself clear - I just want the plot to look like like we all used to draw it when in school. Axes crossing, 4 quadrants, labels right below axis, curve ... as it goes.
Anyone knows how to set it up ?
You should check out two submissions on The MathWorks File Exchange:
PlotAxisAtOrigin by Shanrong Zhang
axescenter by Matt Fig
Hopefully these will work with whatever MATLAB version you have (the submission from Matt Fig is the most recently updated one).
As of Matlab release R2015b, this can be achieved with the axis property XAxisLocation and YAxisLocation being set to origin.
In other words,
x = linspace(-5,5);
y = sin(x);
plot(x,y)
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
Example is taken from MATLAB official documentation:
Display Axis Lines through Origin
Controlling Axis Location