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

Subplot margins (Chapter 1, Exercise 2) #59

Closed
labdmitriy opened this issue Jul 10, 2022 · 1 comment · Fixed by #61
Closed

Subplot margins (Chapter 1, Exercise 2) #59

labdmitriy opened this issue Jul 10, 2022 · 1 comment · Fixed by #61

Comments

@labdmitriy
Copy link
Contributor

Hi @rougier,

There is a statement about additional figure margins for Exercise 2 solution:

# However, we need to have margins in our figure (or tick labels will be cut)
# so we'll have 0.25 inches margin on each side of the axis such that the axis
# will be 4 inches.

And there is a code that performs this adjustment:
inch = 2.54
fig_width = 10.8 / inch # ~4.252 inches
fig_height = 1.25 # 1.250 inches
margin = 0.125 # 0.125 inches
fig = plt.figure(figsize=(fig_width, fig_height))
plt.subplots_adjust(
left=0.5 * margin / fig_width,
right=1 - 0.5 * margin / fig_width,
bottom=0.5 * margin / fig_height,
top=1 - 0.5 * margin / fig_height,
)

It seems that in this case we need to have 0.125 inches margin on each side (not 0.25 as in the description), and margin=0.25 (not 0.125 as in the code) because we multiply this margin by 0.5 when we call plt.subplots_adjust().
Is it correct?

Thank you.

@rougier
Copy link
Owner

rougier commented Jul 11, 2022

You're right. We need 0.125 margin on each side and the 0.5* is confusing (and wrong). Figure in the book seems to be the right size but probably the difference is not noticeable. Can you make a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants