I am trying to draw a COLZ plot i.e. a 2D histogram with a colour bar, from a Tree, and be able to define the number of bins myself.
My Tree is called event:
I have tried:
event->Draw("x:y>>hist1(1000,100,500,1000,0,500)", "x>100");
TH2F * hist1 = (TH2F*)gDirectory->Get("hist1");
hist1->Draw("COLZ");
and:
event->Draw("x:y>>hist1(1000,100,500,1000,0,500)", "x>100", "COLZ");
TH2F * hist1 = (TH2F*)gDirectory->Get("hist1");
hist1->Draw();
But neither will draw the histogram.
This will draw a scatter plot:
event->Draw("x:y>>hist1(1000,100,500,1000,0,500)", "x>100");
TH2F * hist1 = (TH2F*)gDirectory->Get("hist1");
hist1->Draw();
This will draw a COLZ plot but using this method I'm unable to define bin sizes myself:
event->Draw("x:y", "x>100", "COLZ");
I can not reproduce the issue, your first try works for me:
event->Draw("x:y>>hist1(1000,100,500,1000,0,500)", "x>100");
TH2F * hist1 = (TH2F*)gDirectory->Get("hist1");
hist1->Draw("COLZ");
It can also work in a single line:
event->Draw("x:y>>hist1(1000,100,500,1000,0,500)", "x>100", "COLZ");
In your 3rd case, if hist1->Draw(); draws a scatter plot, then hist1->Draw("COLZ"); should work too. Did you run exactly the same way? If so, can you provide a Minimal, Complete, and Verifiable example?
Note: the result of hist1->Draw(); is not a scatter plot (ROOT is misleading here), it is a histogram where bin contents are represented by dots. See e.g. this plot where you can guess the underlying bins.
Thank you for your answer Keldorn but the problem lay within part of my code that I had not posted.
I was accessing my root file using:
TFile f("file.root");
TTree* event = (TTree*)f.Get("EventTree");
Changing this to:
TFile *f = new TFile("file.root");
TTree* event = (TTree*)f->Get("EventTree");
fixed all of my histogram problems!
Related
is there any way to change the smoothing setting via config ?
https://github.com/highcharts/highcharts/blob/master/ts/parts-more/Polar.ts
line 190.
Or do I have to override some functions ? for info - I'm trying to change the interpolation and have got this far. If there is a better way to change the interpolation that would be an acceptable solution.
The problem I am trying to solve is where the interpolated area chart curves actually plot outside of the radar chart because the curvature is too large (ie when every value is at its maximum)
Many thanks
It is impossible to change this value via the config. You can report this idea here: https://github.com/highcharts/highcharts/issues - if core developers will see that this feature is needed they will implement it in the future.
For now, as a workaround, you can overwrite the whole function as a function with changed value.
Demo: https://jsfiddle.net/BlackLabel/j362zfpq/
Highcharts.Series.prototype.getConnectors = function(segment, index, calculateNeighbours, connectEnds) {
var i, prevPointInd, nextPointInd, previousPoint, nextPoint, previousX, previousY, nextX, nextY, plotX, plotY, ret,
// 1 means control points midway between points, 2 means 1/3 from
// the point, 3 is 1/4 etc;
smoothing = 1,
denom = smoothing + 1,
leftContX, leftContY, rightContX, rightContY, dLControlPoint, // distance left control point
dRControlPoint, leftContAngle, rightContAngle, jointAngle, addedNumber = connectEnds ? 1 : 0;
....
}
I would like draw a curved line and attach an object to it. Is it possible to create fraction (from 0.0 to 1.0) which makes move my object on the path? When fraction is 0 then object is on the beginning, when 0.5 is on half way and finally when is on 1.0 it is at the end. Of course i want a curved path, not a straight line :) Is it possible to do in PaintCode?
If you need it only as a progress bar, it is possible in PaintCode. The trick is to use dashed stroke with very large Gap and then just change the Dash.
Then just attach a Variable and you are done.
Edit: Regarding the discussion under the original post, this solution uses points as the unit, so it will be distributed equally along the curve, no matter how curved the bezier is.
Based on the fact that you're going to walk along the curve using linear distance, a thing Bezier curves are terrible for, you need to build the linear mapping yourself. That's fairly simple though:
When you draw the curve, also build a look-up table that samples the curve once, at say 100 points (t=0, t=0.01, t=0.02, etc). In pseudocode:
lut = [];
lut[0] = 0;
tlen = curve.length();
for(v=0; v<=100; v++) {
t = v/100;
clen = curve.split(0,t).length();
percent = 100*clen/tlen;
lut[percent] = t;
}
This may leave gaps in your LUT - you can either fix those as a secondary step, or just leave them in and do a binary scan on your array to find the nearest "does have a value" percentage.
Then, when you need to show your progress as some percentage value, you just look up the corresponding t value: say you need to show 83%, you look up lut[83] and draw your object at the value that gives you.
I tryed to apply to the image the following code in octave:
sq = imread("Square BW.jpg");
figure(1), imshow(Square);
cont1 = edge(sq,"Sobel");
figure(2), imshow(cont1);
The image I get is:
And a similar image appears if I use the Prewitt function. Can anyone explain to me what is happening? The problem is that I can't visualize the process only the result, so I can't understand why the code isn't working.
The problem seems to be how threshold is computed in Octave. You can see how Octave does it by looking at its source by entering type edge at the Octave prompt, or online (I'm not copying the exact code since the code is GPL -- although quite simple)
To get the border, you will need to set the threshold yourself (hopefully, in future versions of Octave's image package this will be fixed but at the moment it's Matlab incompatible since Matlab documentation on their default is unclear).
There's definitely a problem with the way the threshold is computed, however I wasn't able to find the correct value to use in this picture. After many attempts I found this code that seems to work perfectly:
sq = imread("Square BW.jpg");
maskSobel = fspecial("sobel");
mSobel = uint8(zeros(size(BW)));
for i = 0:3
mSobel += imfilter(sq, rot90(maskSobel, i));
end
figure(1), imshow(mSobel);
First we create the Sobel matrix/operator and a zero matrix the same size of the image Square BW. Then we rotate the Sobel matrix four times (by 90 degrees), in order filter the image in all directions (left-right, up-down, right-left and down-up), always adding the result to the mSobel matrix that was created.
Here's the final result:
I've added a gradient to my scatter plot in the usual manner:
CPTFill areaGradientFill = [CPTFill fillWithGradient:areaGradient1];
boundLinePlot.areaFill = areaGradientFill;
boundLinePlot.areaBaseValue = 0;
Setting the minimum for the gradient is easy to do with the areaBaseValue property. However, the gradient will always stretch such that the entire range of color defined by areaGradient1 appears below the line plot.
What I'd like to do is set an absolute y-axis range (e.g., 0 to 100) and have the gradient always be set to that range. So if my line is at y=50, only the bottom 50% of the gradient would be rendered below the line. I thought setting boundLinePlot.areaBaseValue2 = 100; would do this, but it doesn't have any effect.
Does CorePlot support this? If not, what's the 'right' way to go about implementing it?
(This is my first question so apologies if I'm not clear. Be gentle. :) )
While there's no direct way to make this happen you could use a trick. Make your horizontal global range wider than what you would show normally and do not make the graph horizontally scrollable. Add a value to the graph in the hidden area that is always your maximum value. This will be filled with the full gradient. Other parts however will only get a partial gradient, depending on their height.
I found this trick by accident while looking at one of my graphs. Look:
The overview at the top shows where the big graph is currently (the green limit band). Now compare this with another part:
You can clearly see that the tip of the large value has a different gradient value as the tip of the smaller one.
You can use a "background limit band" to draw a fill at a certain size behind the plots, but that won't be clipped to the plot line.
I hope this question is beyond "read the manual". My task is simple, just to plot the following, but the plot in the middle should be a filled.contour plot:
http://gallery.r-enthusiasts.com/graph/Scatterplot_with_marginal_histograms_78
Background: I prefer filled.contour rather than hist2d. Because, I could use kernel smooth, so the plot for discrete data won't be too ugly. I also tried image() and then contour(), but the number on contour is not clear and no indication about the color.
My problem: in filled.contour function, it uses layout() for filledcontour() plot and rect() plot (color bar). However, I use layout() in the outside code to organize 2 histogram and one filled.contour plot. Looks like, the layout outside is shadowed by filled.contour(). I am not sure how R deal with this problem. Should I rewrite filled.contour() somehow?
Thanks
If you look at the help page ?filled.contour you will see that it also mentions another function called .filled.contour (extra . at the front) which does just the bare bones plotting without calling layout and causing the problems that you see. You need to do more of the checking and prelim work, but you should be able to do what you want using .filled.contour for the main plot and setting up the layout yourself.