Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reduce image size in episodes #144

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions _episodes/01-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ plt.show() # Show the figure

This code produces the following figure:

<!-- ![basic_plot](https://matplotlib.org/stable/_images/sphx_glr_usage_002.png) -->
![basic_plot](https://matplotlib.org/3.5.1/_images/sphx_glr_usage_001_2_0x.png)
![basic_plot](https://matplotlib.org/3.5.1/_images/sphx_glr_usage_001_2_0x.png){:width="50%"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I'd imagine something like max-width would work better here. Else it will be very small when viewing the page in split-screen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what would be the syntax for max-width that would work here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I wonder. Maybe the {:width} thing is arbitrary html attribute injection though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does {:max-width=xxxpx} work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we can inject classes, so worst case would be to define a CSS class and then assign that


> ## Notice
> If you look at the plot and the order of the list of numbers you can clearly see that the order of the arguments is of the form
Expand All @@ -61,15 +60,15 @@ This code produces the following figure:
> Both methods allow you to produce a plot like the following *(we will later see how to produce them in more detail)*
> > ## See example plot
> >
> > ![3linesplot_ver1](../fig/3linesplot_ver2.png)
> > ![3linesplot_ver1](../fig/3linesplot_ver2.png){:width="50%"}
> {: .solution}
{: .callout}

# What goes into a plot?

Now, let's have a deeper look at the components of a Matplotlib figure.

![Names for different parts of a matplotlib plot](https://matplotlib.org/stable/_images/anatomy.png)
![Names for different parts of a matplotlib plot](https://matplotlib.org/stable/_images/anatomy.png){:width="50%"}

## How to work with some of these elements?

Expand Down Expand Up @@ -256,7 +255,7 @@ hep.style.use("CMS") # string aliases work too

and with just this addition we can produce the same plot as before with this new look.

![mplhep-figure](../fig/mplhep_fig.png)
![mplhep-figure](../fig/mplhep_fig.png){:width="50%"}

> ## Warning
>
Expand Down Expand Up @@ -293,7 +292,7 @@ ax.errorbar(bin_centers, counts, yerr=np.sqrt(counts), fmt="none")
plt.show()
```

![first histogram](../fig/first_histo.png)
![first histogram](../fig/first_histo.png){:width="50%"}

# More information?

Expand Down
14 changes: 7 additions & 7 deletions _episodes/04-higgs-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ ax.hist(branches["data_A"]["m4l"])
~~~
{: .output}

![m4lep_histogram_0]({{ page.root }}/fig/m4lep_histogram_0.png)
![m4lep_histogram_0]({{ page.root }}/fig/m4lep_histogram_0.png){:width="50%"}

**Tip:** In the previous plot the numbers in the axis are very small, we can change the font size (and font family) for all the following plots, including in our code:

Expand Down Expand Up @@ -176,7 +176,7 @@ ax.hist(branches["data_A"]["m4l"])
~~~
{: .output}

![m4lep_histogram_1]({{ page.root }}/fig/m4lep_histogram_1.png)
![m4lep_histogram_1]({{ page.root }}/fig/m4lep_histogram_1.png){:width="50%"}

> ## Exercise
>
Expand All @@ -199,7 +199,7 @@ ax.hist(branches["data_A"]["m4l"])
> > ax.set_ylabel("Events")
> > ax.legend()
> > ```
> > ![m4lep_histogram_2_0]({{ page.root }}/fig/m4lep_histogram_2_0.png)
> > ![m4lep_histogram_2_0]({{ page.root }}/fig/m4lep_histogram_2_0.png){:width="50%"}
> {: .solution}
{: .challenge}

Expand Down Expand Up @@ -280,7 +280,7 @@ We certainly can visualize this information with Matplotlib making a histogram :
> > ax.set_ylabel("Events")
> > ax.legend(frameon=False)
> > ```
> > ![cut_histogram_3]({{ page.root }}/fig/cut_histogram_3.png)
> > ![cut_histogram_3]({{ page.root }}/fig/cut_histogram_3.png){:width="50%"}
> {: .solution}
{: .challenge}

Expand Down Expand Up @@ -434,7 +434,7 @@ ax_2.tick_params(which="both", direction="in", top=True, right=True, length=6, w
ax_2.legend(frameon=False)
```

![MC_histogram_4]({{ page.root }}/fig/MC_histogram_4.png)
![MC_histogram_4]({{ page.root }}/fig/MC_histogram_4.png){:width="70%"}

# Data samples

Expand Down Expand Up @@ -496,7 +496,7 @@ ax.set_ylim(0, 30)
ax.legend(fontsize=18, frameon=False)
```

![m4lep_histogram_5]({{ page.root }}/fig/m4lep_histogram_5.png)
![m4lep_histogram_5]({{ page.root }}/fig/m4lep_histogram_5.png){:width="50%"}
> ## Exercise
>
> Modify a bit the previous code to include the ticks and text, in the text and axis labels use latex to achieve the final plot.
Expand Down Expand Up @@ -529,7 +529,7 @@ ax.legend(fontsize=18, frameon=False)
### Final Plot

You can see at 125 GeV the component corresponding at the Higgs boson.
![m4lep_histogram_6]({{ page.root }}/fig/m4lep_histogram_6.png)
![m4lep_histogram_6]({{ page.root }}/fig/m4lep_histogram_6.png){:width="50%"}

**Bonus**: If you are more curious about other HEP analysis tools, you can take a look at this same example developed with the ROOT framework [here](https://root.cern.ch/doc/v622/df106__HiggsToFourLeptons_8py.html).

Expand Down
14 changes: 7 additions & 7 deletions _episodes/05-mplhep.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fourlep = pd.concat(csvs)
In this chapter we will see how to use mplhep commands to make a quality plot.

This is our goal
![](../fig/Hto4lep_plot.png)
![](../fig/Hto4lep_plot.png){:width="80%"}

## Let's begin!

Expand Down Expand Up @@ -130,12 +130,12 @@ fig.show()

This would plot the following figure.

![](../fig/zz.png)
![](../fig/zz.png){:width="70%"}

> ## Exercise
> Plot each of the backgrounds individually. You should have something similar to
> ![](../fig/drellyan.png)
> ![](../fig/ttbar.png)
> ![](../fig/drellyan.png){:width="50%"}
> ![](../fig/ttbar.png){:width="50%"}
{: .challenge}

### Stacking histograms and adding the CMS logo.
Expand Down Expand Up @@ -211,7 +211,7 @@ yerrs = np.sqrt(hist)
>
>fig.show()
>```
> ![](../fig/background+data.png)
> ![](../fig/background+data.png){:width="80%"}
{: .solution}

# Putting it all together
Expand Down Expand Up @@ -248,7 +248,7 @@ ax.set_xlim(rmin, rmax)
fig.show()
```

![](../fig/hzz.png)
![](../fig/hzz.png){:width="70%"}

> ## Bonus question: how can something, that seems to have a mass of roughly 125 GeV decay via two Z bosons, with mass over 90 GeV?
>Add that graph with all background + data and see how it lines up.
Expand Down Expand Up @@ -307,7 +307,7 @@ fig.show()
>```
{: .solution}

![](../fig/final-plot.png)
![](../fig/final-plot.png){:width="80%"}

# Done! We are ready to publish :)

Expand Down
10 changes: 5 additions & 5 deletions _episodes/07-dimuonspectrum.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ax.set_title("Muon Mass spectrum")
plt.show()
```

![png](../fig/output_15_0.png){: width="560px"}
![png](../fig/output_15_0.png){:width="50%"}

Doesn't really look like much. How about we fix that!

Expand All @@ -197,9 +197,8 @@ Using the code above, zoom in and fix the above plot to help **visually** estima
>plt.show()
>```
>
>![png](../fig/output_17_0.png){: width="560px" .image-with-shadow }
>![png](../fig/output_17_0.png){: width="50%" .image-with-shadow }
{: .solution}
>

# Let's make the dimuon spectrum

Expand Down Expand Up @@ -363,7 +362,7 @@ You could use the `np.logspace()` function for the binning. It helps in returnin
>```
{: .solution}

![png](../fig/output_26_0.png){: width="560px"}
![png](../fig/output_26_0.png){:width="50%"}

Depending on what you did, you may see hints of particles below $$20 GeV/c^2$$. It is possible you see signs of other particles at even higher energies. Plot your masses over a wide range of values, but then zoom in (change the plotting range) on different mass ranges to see if you can identify these particles.

Expand All @@ -373,6 +372,7 @@ Image(
)
```

<img src="https://twiki.cern.ch/twiki/pub/CMSPublic/HLTDiMuon2017and2018/CMS_HLT_DimuonMass_Inclusive_2017.png"/>

![CMS_HLT_DimuonMass_Inclusive_2017](https://twiki.cern.ch/twiki/pub/CMSPublic/HLTDiMuon2017and2018/CMS_HLT_DimuonMass_Inclusive_2017.png){:width="70%"}

{% include links.md %}