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

Chapter 1: Bug in plotting prior & posterior probabilities due to giving lw a string as an input #560

Open
mark-yong opened this issue Jun 29, 2023 · 1 comment

Comments

@mark-yong
Copy link

mark-yong commented Jun 29, 2023

Attempting to execute the following code in Ch 1 results in TypeError: must be real number, not str:

figsize(12.5, 4)
colours = ["#348ABD", "#A60628"]

prior = [0.20, 0.80]
posterior = [1.0 / 3, 2.0 / 3]
plt.bar(
    [0, 0.7],
    prior,
    alpha=0.70,
    width=0.25,
    color=colours[0],
    label="prior distribution",
    lw="3",
    edgecolor=colours[0],
)

Changing the code to the following where lw=3 instead of '3' fixes the problem

figsize(12.5, 4)
colours = ["#348ABD", "#A60628"]

prior = [0.20, 0.80]
posterior = [1.0 / 3, 2.0 / 3]
plt.bar(
    [0, 0.7],
    prior,
    alpha=0.70,
    width=0.25,
    color=colours[0],
    label="prior distribution",
    lw=3,
    edgecolor=colours[0],
)

Matplotlib's documentation for set_linewidth states the function only expects floats; strings this may have worked in previous versions, but the current version may have broken something

    def set_linewidth(self, w):
        """
        Set the patch linewidth in points.

        Parameters
        ----------
        w : float or None
        """

https://github.com/matplotlib/matplotlib/blob/v3.7.1/lib/matplotlib/patches.py#L384

Advise to always use numbers when setting linewidth instead of strings

Version of matplotlib: 3.7.1

@mark-yong
Copy link
Author

mark-yong commented Jul 1, 2023

PRs 557 & 559 both appear to be attempts to fix this issue

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

No branches or pull requests

1 participant