Skip to content
Snippets Groups Projects
Commit cd1d2928 authored by Carla Elena Gomez Alvarado's avatar Carla Elena Gomez Alvarado
Browse files

archivos agregados desde el jupyterhub

parent 13224b86
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
#This code meants to be generic to analyze data from a .root file using ROOT.
At this time the data is a file from (insert path to gitmilab) .csv file
wich relates etnies with height.
%% Cell type:code id: tags:
``` python
import ROOT
import uproot
import matplotlib.pyplot as plt
```
%% Output
Welcome to JupyROOT 6.18/04
%% Cell type:code id: tags:
``` python
# activates javascripts for interactive graphs.
%jsroot on
```
%% Cell type:code id: tags:
``` python
#data anlysis using root
#open .root file and named it "data"
data = ROOT.TFile.Open("/home/student/ejercicios-clase-08-datos/codigo/data_analisis.root")
```
%% Cell type:code id: tags:
``` python
#define canvas , named "canva", and Title "Height vs Race"
canva = ROOT.TCanvas("Canvas","Height vs Race",800,600)
```
%% Cell type:code id: tags:
``` python
#define a tree to store .root file form the spreadsheet "data_analisis"
tree = data.Get("data_analisis")
```
%% Cell type:code id: tags:
``` python
# To know how many entries has the file
tree.GetEntries()
```
%% Output
32
%% Cell type:code id: tags:
``` python
#Build the histogram using ROOT.
# Data_ analysis has 4 countries each of them represents a colum on the X axis.
hist = ROOT.TH1F("hist_data"," Height vs Origen; Origen ; Height " ,4,-0.5,4.5)
```
%% Cell type:code id: tags:
``` python
for origen in tree:
hist.Fill(tree.tamano)
print("Done!")
```
%% Output
Done!
%% Cell type:code id: tags:
``` python
hist.SetFillColor(40)
hist.Draw()
```
%% Cell type:code id: tags:
``` python
canva.Draw()
```
%% Output
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
file = uproot.open("/home/student/ejercicios-clase-08-datos/codigo/data_analisis.root")
```
%% Cell type:code id: tags:
``` python
file.keys()
```
%% Output
[b'data_analisis;1']
%% Cell type:code id: tags:
``` python
#plt.title('Titulo')
plt.figure(figsize=(10,10))
plt.ylabel('Tamaño')
plt.xlabel('Origen')
plt.bar(x=analisis['tree.origen'], height=analisis['tree.tamano'])
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-33-dcded93941c6> in <module>
3 plt.ylabel('Tamaño')
4 plt.xlabel('Origen')
----> 5 plt.bar(x=analisis['tree.origen'], height=analisis['tree.tamano'])
NameError: name 'analisis' is not defined
%% Cell type:code id: tags:
``` python
```
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment