I have a PyQtGraph plot, that can be zoomed or panned. It changes its ranges. Cannot I somehow get known, when a plot changes its ranges?
Connect your chosen method (slot) to the PlotItem.sigRangeChanged signal (see http://www.pyqtgraph.org/documentation/graphicsItems/plotitem.html )
Related
Following plot has a error series Series2 which is not displayed on this chart, but legends says about its existence. This series needs to be displayed with minimum y value as infinity. But, Tee chart doesn't have any provision to specify -Infinity directly. So, we defined a huge negative number instead; which is significantly larger than the y axis to give an appearance of -Infinity to the user. But, if the chart area becomes too small compared to this huge negative number, the series (here series2) vanishes entirely.
Here is the series data used -
Series2 Points:
X-------------------->>Bar-------------------->>Std. Error
1432 --------->> -50.19380462 ----------->> 50.20619538
1797 ---------->> 50.19380462 ----------->> 50.20619538
2164 ---------->> -50.19380462 ----------->> 50.20619538
2529 --------->> -50.19380462 ----------->> 50.20619538
Can anyone please help to resolve this issue?
Thanking you.
The next release of TeeChart for .NET includes support for extended Axis ranges, from Double.MinValue to Double.MaxValue, and goes some way further to handle infinite value issues. That doesn't say for sure that it will resolve the issue you describe here. If you are able to send Steema Support a sample project that shows the issue we can test it with the new release.
I have highlighted specific activities (feeding,resting and sleeping) from the dataset in my plot. Now I want to connect these highlighted points in sequence over my polar coordinates.
Here's my dataset:
Activity Latitude Longitude
Feeding 21.09542 71.06014
Resting 21.09564 71.06064
Sleeping 21.09619 71.06128
Walking 21.09636 71.06242
Walking 21.09667 71.06564
Resting 21.09483 71.06619
Can you help me out in this?
# Example dataframe
set.seed(1)
mydf=data.frame(Activity=sample(c("Walking","Feeding","Resting","Sleeping"),20,T),Latitude=rnorm(20,21,0.5),Longitude=rnorm(20,71,0.5))
mydf$Order=1:nrow(mydf)
If you want to connect the points in order regardless of the activity, do the following (for clarity, I added the variable mydf$Order to label the points).
# Plot
library(ggplot2)
ggplot(data=mydf)+
geom_point(aes(x=Latitude,y=Longitude,colour=Activity))+
geom_path(aes(x=Latitude,y=Longitude))+
geom_text(aes(x=Latitude,y=Longitude,label=Order))+
coord_polar(theta="y")
If you want to connect points according to activities, consider CMichael's answer.
Ok I am starting from scratch: My original answerwas much too bulky and inflexible.
Just add the following to get Paths for each Activity without filtering.
+ geom_path(aes(colour=ACTIVITY,x=Latitude,y=Longitude))
If you want to plot only selected Activities:
+ geom_path(data=Data[Data$ACTIVITY %in% c("Sleeping","Resting"),],aes(colour=ACTIVITY,x=Latitude,y=Longitude))
The selected Activities are to be listed in the c(...) vector with each name quoted.
UPDATE: OP clarified that he wants to connect any stationary point, this achieved by running the following:
+ geom_path(data=Data[Data$ACTIVITY!="Walking",],colour="red",aes(x=Latitude,y=Longitude))
Note that the colour=ACTIVITY is removed from the aesthetics and we consider all stationary points (!="Walking") to draw the path.
Code combining the two answers:
set.seed(1)
mydf=data.frame(Activity=sample(c("Walking","Walking","Walking","Walking","Walking","Resting","Feeding","Sleeping"),20,T),Latitude=rnorm(20,21,0.5),Longitude=rnorm(20,71,0.5))
mydf$Order=1:nrow(mydf)
# Plot
library(ggplot2)
ggplot(data=mydf)+
geom_point(aes(x=Latitude,y=Longitude,colour=Activity),size=5)+
geom_path(aes(x=Latitude,y=Longitude),size=1.2)+
geom_text(aes(x=Latitude,y=Longitude,label=Order))+
geom_path(data=mydf[mydf$Activity!="Walking",],colour="red",aes(x=Latitude,y=Longitude)) +
coord_polar(theta="y")
I am using d3.js to draw charts, however there are sections where there's no data and it obviously drops to zero. Like this:
I was wondering if there's anyway to end the line right as the data becomes zero and then resumes when there's data again? I'm not sure how to even go about this.
Thanks for your help!
on the line generator add this:
.defined(function (d) { return d.y != 0;})
it will prevent the line from going all the way down to the axis
I am trying to write a Matlab script to analyze two specific sets of data, create histograms for them, and write them to a single file where you can see both histograms overlapped on one plot.
I created a functioning script that created the histogram for 1 set of data that basically went like this:
h1=figure;
hist(data,nbins:;
print(h1,'-dpng','hist.png)
Then I tried to simply add a second line of:
h2=figure;
and changed the print function to include h2. That obviously didn't work. I found that I couldn't have both an h1 and an h2 with the print function.
After searching the internet and looking for ways to get around this I decided to try to use saveas instead. I got to the following:
h=findobj(gca,'Type','patch');
hist(data1,nbins);
hold on;
hist(data2,nbins);
set(h(1),'FaceColor','r','EdgeColor','k');
set(h(2),'FaceColor','b','EdgeColor','k');
saveas(h,'-dpng','hist.png')
But this won't quite work either. I haven't found anything on the Mathworks website that helps me with this problem, and I haven't found anything on any other site either. I am using a Linux computer connecting to a different server via SSH so the only way that I can view plots that I make is by saving them to a file and then opening them. Please let me know if you have any suggestions to accomplish my task as outlined in my first paragraph. Thank you.
One way is to use different axes for different histogram. You can use SUBPLOT for this:
subplot(2,1,1)
hist(data1,nbins);
subplot(2,1,2)
hist(data2,nbins);
Another way is to find a common bins (x) and return the hist output to vectors. Then use BAR function for the plot.
nbins = 20;
x = linspace(min([data1(:);data2(:)]),max([data1(:);data2(:)]),nbins);
h1 = hist(data1, x);
h2 = hist(data2, x);
hb = bar(x,[h1(:),h2(:)],'hist');
% change colors and set x limits
set(hb(1),'FaceColor','r','EdgeColor','k');
set(hb(2),'FaceColor','b','EdgeColor','k');
gap = x(2)-x(1);
xlim([x(1)-gap x(end)+gap])
I'm using the matlab GA and the plot option 'gaplotrange'. But I'm running matlab on a Linux server through a terminal. So when I try to save the gaplot, I either keep getting an empty image (if I use saveas) or an error (if I use print, I get a message saying it is not supported in the current platform).
Is there any other way I could save the plot in the nodisplay mode?
Here is a piece of my code
opts = gaoptimset('PopulationSize', 256, 'EliteCount',1,'CrossoverFraction',0.8, ...
'Generation', 3, 'PenaltyFactor',80,'SelectionFcn',{#selectiontournament,4}, ...
'CrossoverFcn', #crossoverscattered ,'Vectorized','off', 'UseParallel','always',...
'OutputFcns',#pop_output,'MutationFcn',{#mutationuniform,0.002},'StallGenLimit',3,...
'TolFun', 1e-4,'PlotFcns',#gaplotbestf);
f = figure('vis','off');
[x,fval, exitflag, output, population, scores] = ga(#plate_fitness,16,[],[],[],[],vlb,vub,[],opts);
hgsave(f,'matlabga_range','png');
Matlab has a solution for this one posted here
hgsave('filename')
hgsave(h,'filename')
I don't have much experience with the genetic algorithms toolbox, but a quick glance at the docs shows this
To display a plot when calling ga from the command line, set the PlotFcns field of options to be a function handle to the plot function. For example, to display the best fitness plot, set options as follows
options = gaoptimset('PlotFcns', #gaplotbestf);
So if you're not passing 'PlotFcns' with a handle to the plotting function in, it looks like it won't generate the plot based on command line interaction. Add it in and see if it fixes your problem, more details here
Update:
Turns out the problem was that the ga method's plot was creating its own figure, so the save needed to be on the gcf, see the discussion below for more details.