real time plotting on iPhone using core plot? - iphone

I want to use core-plot for drawing line graph dynamically. data won't come at a time, we will be receiving point by point dynamically.
Is it possible to draw the chart dynamically using core-plot i.e drawing point by point as on when we receive the (x,y) point?
Please help me, Thanks.

Yes, you can do this reasonably easily. For each received data point, append it to an array of values to display. As these data points come in, call -reloadData on the Core Plot graph (or just the particular plot) to redraw the graph, passing in the array you just added a value to in response to the -numbersForPlot:field:recordIndexRange: delegate method.
If you need to adjust the plot range to track your data points (for a moving ticker), recalculate the new CPPlotRange for the X axis and set the plot space's xRange property to that.
Use the CPTestApp-iPhone, AAPLot, or StockPlot examples as templates for how to set up the line chart overall, and modify from that starting point.
I do something similar to this on the Mac in a scientific application:
(source: sunsetlakesoftware.com)

Sounds like you could make use of a demo project I put together and wrote about here (not core plot related though).
It draws a EKG graph but should easily be modified to use another input than the repeated "heart beat"...See line 320 in EAGLView.m where the indata is entered into the array.

Related

How To Plot custom images as markers over a Polarplot()?

I want to create a polarplot() on which I want to plot custom bitmaps/images as marker.
Also, I want to animate the polarplot() by updating these marker's location in regular time intervals(500milliseconds).
Please see the below attached image to get an idea what I want.
SamplePlotExample.jpg
I have made a similar application using 'polar()' and 'imagesc()'.
But I feel 'polarplot()' is better and recommended by Matlab.
Also there are so many customization options available with polarplot().
But I am unable to use imagesc() with polarplot because of some polar coordinate-to-cartersian coordinate conversion problem.
Pleas give solution.
Is there any other better methods to follow?

Matlab Link data for a line graph on a scatter plot

I have a line which is plotted on another scatter plot. This line changes its shape from time to time. Is there any way by which I can specify in my program that the data for drawing this line is dynamic so that the plot updates by itself when the data changes?
Now what I am doing is draw the entire figure again after each data update. The program has very large number of iterations(>5000) and I need to visualize every change. That means figure should be drawn 5000 times. This is making my program very slow. Is there any other better way of doing this?
The refreshdata function might do what you want.
To automatically update a graph when a source variable changes, use the linkdata function. MathWorks has a is a great introduction page. However, there is a short example in the documentation:
x = [1:20];
y = rand(20,3);
area(x,y)
linkdata on
Then you can change a variable and the plot automatically redraws:
y(10,:) = 0;
Automatic update.
Note: Changing the source to a different variable entirely is a different thing. If YDataSource is reassigned, then refreshdata would be needed, as pointed out by Molly. Otherwise, this will keep your plot up-to-date when the variable changes.
One caveat is described on this page:
linkdata buffers updates to data and dispatches them to plots at roughly half-second intervals. This makes data linking not suitable for smoothly animating changes in data values unless they are updated in loops that are forced to execute two times per second or less.

Matlab: linkaxes squeezes my graph

I have drown several graphs thanks to "subplot" function on MatLab and it works well.
Nevertheless, I want all my graphs to have the same Y-scale so that I can compare them.
I used the "linkaxes" function and my all my graphs have the same scale but the problem is that some of my figures are "beheaded", lacking their upper part, or one of my figures is completely squeezed.
I don't get what happened. Could you please help me to solve the problem or tell me about another function that would be more appropriate in my case?
Here's part of my code:
for i=1:1:9
m=n(i);
fichier=sprintf('%d.txt',m);
M=load(fichier);
z=length(M(:,1));
x=M(1:z,1);
y=M(1:z,2);
a(i)=subplot(2,4,i)
contour3=plot(x,y)
linkaxes(a,'y')
end
linkaxes creates a permanent link between the scales of several axes, so that you can subsequently perform zoom operations (perhaps interactively) on one, and have the other automatically update.
If you need that functionality, then linkaxes is the right command (although you could possibly also look at linkprops).
However if all you need is to ensure that the y-axis limits of your axes are the same, it will probably be easier (and you will have more control) if you set them directly. You can retrieve the y-axis limits using ylim(axis_handle) and set them using ylim(axis_handle, [lower, upper]), or alternatively with get(axis_handle,'YLim') and set(axis_handle,'YLim',[lower,upper]). You might also look at the YLimMode property of the axis, which determines whether the axis limits are directly set or automatically resized.

Highlight a single plot symbol on a line - Core Plot

I'm making an iPhone app that uses Core Plot at one point in the application. I'm drawing a graph using a CPTScatterPlot and along the line I have CPTPlotSymbol plot symbols.
the graph is looking really good after some customizing but what I want to do is give the user a bit better visual representation of where exactly on the graph the current material is referring to.
I would like to "highlight" individual plot symbols along my line. I have the location on the xAxis of the point I want to manipulate. I have not been able to find any example of this or even a suggestion that it's possible, it seems to be possible for pie charts and bar plots though.
If it is not possible to change or manipulate the actual plot symbol at a point I'm quite happy to simply draw something over the symbol. If so, is there a way to get the x,y coordinates (in relation to the screen) of each plot symbol? Or will I have to calculate that from my data? My data varies a_lot so I'm simply auto resizing the plot area at the moment.
thanks!
You can implement the -symbolForScatterPlot:recordIndex: datasource method to customize the plot symbol at each point. Return nil if you don't want a symbol drawn at the given index. The Mac version of CPTTestApp (in the Core Plot examples folder) has a plot symbol demo that shows how to use this method.

how to restrict scrolling for +ve part in cpxygraph

I am new to core plot SDK, implemented core plot in my app. i need to restrict -ve part of graph. i.e always i will have +ve values for graph((1,1),(10,15),(20,15)).i need horizontal , vertical scrolling for +ve part only.So i want to restrict remaining 3 parts of graph. I tried in all ways help less, so posted here. if any one already done with this type requirement, please help me ASAP.
Thanks in advance.
The easiest way to restrict the scrolling ranges is to set the globalXRange and globalYRange properties on your plot space. If you want more control, you can use a plot space delegate. CPTestApp (the Mac version) demonstrates both techniques.