How can I convert a histogram (2D) into 2 pdf in zfit? - zfit

I am trying to do some 2d spectra fitting with the help of zfit.
The pdf I want to use comes from ROOT TH2D.
Is there any method to convert the input Th2D into a 2D pdf directly in zfit?
Thanks a lot!

Update
zfit supports now binned PDFs (see here) in the newest version (to be installed with pip install -U zfit --pre) and allows to load histograms. They should be a Histogram from hist if possible, using uproot you should be able to convert one to another.
An introductory tutorial to binned fits can be found here
Old answer
There is currently no direct way but there is Work In Progress to implement binned fitting.
In general, I would advise to use hist within Python, as it can be used directly with zfit in the future.
A way to implement this now is to use the hists density, create a custom PDF (such as here) in zfit and set zfit.run.set_graph_mode(False) and zfit.run.set_autograd_mode(False).

Related

I need a special type of charts and don't know which chart plotting program support it

I would need create a chart like the one on the picture. I don't want to draw it by hand, since I need more of them. I prefer R CRAN for drawing charts, but would do also any other programming or plotting program. If possible pdf or eps outputs are preferable. Does anybody have an idea, what type of chart, or which R (or other SW) package would support something like that?
I have found the solution. Orange software package makes the charts.
https://docs.orange.biolab.si/3/data-mining-library/reference/evaluation.cd.html

Can I plot the SVM decision boundary for 3 features(in 3D space) using Scikit learn?

I am using scikit-learn to understand Support Vector Machines(SVM). I want to plot the decision boundary computed by SVM. The SVM uses 3 features. So the decision boundary must be drawn in 3D space. Is this possible using scikit-learn?
I could find only 2D plots of SVM decision boundary at the official website.
However I found links on stackoverflow which show this is possible using matlab and r. Is there a way in which I can achieve the same using scikit-learn?
You don't use scikit-learn to plot things in Python. You have to use another package, and if you check scikit-learn's examples, you will see they use matplotlib. You can create 3D plots with matplotlib, here is the tutorial. The usage is basically the same than in 2D, except you add an argument for the third dimension.
Another popular package you could use is mayavi, which was conceived especially for 3D plotting.

Editing multiple plots in Rstudio

One interesting feature of RStudio is it allows to save multiple plots generated from a script. This however opens up the problem of how to edit multiple plots. My issue at the moment is adding lines to histograms using the abline() function. This function was designed however to work with the last plot generated by the environment. One way of course would be ad the lines as soon as the plot is generated, however I have to calculate the coordinates at the end of the algorithm, by then I have transformed the data and generated multiple plots from it. So I was wondering if there isn't a way to tell R to search for a given plot and add the line to it. I read abline() documentation but found nothing regarding it. One can always save the data necessary to generate the plot and generate it at the end of the script, but I was wondering if there isn't a less consuming memory method.
One way to get around this issue is:
1.Save your graphics as variables, for ex: hist_1=hist(x, plot=FALSE)
2.Write any code u like, for ex: very complicated code give y as a number for output
3.plot(hist_1)
4.abline(hist_1, v=y)
gives a general idea of how to edit multiple plots without having to save multiple copies of datasets and without overloading Rstudio interface. Works well with the R ubuntu terminal too.

Is there an interactive output device to view 3D graphs in R?

I'm currently generating 3D graphs in R using the persp-command. To change the viewpoint one has to set the parameters theta and phi. To evaluate (a good viewpoint on) the graph, one has to try lots of combinations for these parameters.
I was wondering if one can define an interactive output device that allows to rotate the graph using the mouse. It would be also nice if this device gives the current values for theta and phi.
Is there such a device/package?
See the rgl package: http://cran.r-project.org/web/packages/rgl/index.html
It won't report the theta and phi values you need, IIRC (though see #Dieter's comment below for a solution to this), but you can use rgl.snapshot() or rgl.postscript() to grab the current display as a bitmap or vector image. The package has persp3d() which is very similar to persp().
See the package rggobi http://cran.r-project.org/web/packages/rggobi/index.html
For data visualisation in 3 or even more dimensions, try the package rggobi which makes use of the program ggobi. It is possible to manipulate the data using the mouse, "brush" data, identify points in the data all while visualizing in a number of dimensions.

Plotting large numbers with R, but not all numbers are being shown

I am trying to render 739455 data point on a graph using R, but on the x-axis I can not view all those numbers, is there a way I can do that?
I am new to R.
Thank you
As others suggested, try hist, hexbin, plot(density(node)), as these are standard methods for dealing with more points than pixels. (I like to set hist with the parameter breaks = "FD" - it tends to have better breakpoints than the default setting.)
Where you may find some joy is in using the iplots package, an interactive plotting package. The corresponding commands include ihist, iplot, and more. As you have a Mac, the more recent Acinonyx package may be even more fun. You can zoom in and out quite easily. I recommend starting with the iplots package as it has more documentation and a nice site.
If you have a data frame with several variables, not just node, then being able to link the different plots such that brushing points in one plot highlights them in another will make the whole process more stimulating and efficient.
That's not to say that you should ignore hexbin and the other ideas - those are still very useful. Be sure to check out the options for hexbin, e.g. ?hexbin.

Resources