Skip to content

Commit 93bc44a

Browse files
authored
Update scientific-figures.md
1 parent f10e319 commit 93bc44a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

programming-notes/python/scientific-figures.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,42 @@ with plt.style.context('science'):
151151
fig.savefig('fig1.pdf', dpi=300, bbox_inches='tight') # Save figure in pdf
152152
```
153153

154+
## Sizing images correctly
155+
156+
If a journal's style guide tells the widths of the columns, you can use those values when generating your figure. If it doesn't tell the width, you can use the `printlen` LaTeX package to print it out inside your document:
157+
158+
```latex
159+
...
160+
% In the preamble
161+
\usepackage{printlen}
162+
...
163+
% In a figure environment
164+
\begin{center}
165+
\includegraphics[width=\columnwidth]{example_fig}
166+
\end{center}
167+
\caption{%
168+
\label{fig:example_fig}
169+
In this figure caption, I can see that the width of
170+
one column is \printlength{\columnwidth}.}
171+
...
172+
```
173+
174+
Once we find the correct width, we use it in our python script:
175+
176+
```python
177+
pt = 1./72.27 # 72.27 points to an inch
178+
179+
jour_sizes = {
180+
"PRD": {"onecol": 246*pt, "twocol": 510*pt},
181+
"CQG": {"onecol": 374*pt}, # CQG is only one column
182+
# Add more journals below. Can add more properties to each journal
183+
}
184+
185+
width = jour_sizes["PRD"]["onecol"]
186+
187+
# Our figure's aspect ratio using the golden ratio
188+
golden = (1 + 5 ** 0.5) / 2
189+
my_height = my_width/golden
190+
191+
fig = plt.figure(figsize=(my_width, my_height))
192+
```

0 commit comments

Comments
 (0)