Why plotly? And some prerequisites.#

Learning Objectives#

After working through this topic, you should be able to:

  • explain why we use plotly

  • describe why it is hard to have great interactive and static functionality in one library

  • export static figures using kaleido regardless of the OS you are using

Materials#

Here is screencast. These are the slides.

Quiz#

from jupyterquiz import display_quiz

content = [
    {
        "question": ("The main advantages of plotly are:"),
        "type": "many_choice",
        "answers": [
            {
                "answer": "It produce interactive graphs",
                "correct": True,
                "feedback": "Correct. Interactive graphs are very helpful \
                    to direct more formal analyses",
            },
            {
                "answer": "It is available for additional statistical softwares",
                "correct": True,
                "feedback": "Correct. It's available also in Julia and R.",
            },
            {
                "answer": "Supports relevant output formats",
                "correct": True,
                "feedback": "Correct. E.g. dashboards, HTML, static formats",
            },
            {
                "answer": "It produces particularly nice graphs",
                "correct": False,
                "feedback": "Incorrect. The graphs produced by different \
                    libraries are comparable.",
            },
        ],
    },
    {
        "question": (
            "Static and interactive plots are hardly ever \
                integrated in a single library because:"
        ),
        "type": "multiple_choice",
        "answers": [
            {
                "answer": "Dynamic plots are typically based on JavaSript \
                    while static graphs do not need it",
                "correct": True,
                "feedback": "Correct. In plotly, Kaleido tries to bridge \
                    this difference by running a browser in the background \
                    and downloading a static graph.",
            },
            {
                "answer": "The library would be too big",
                "correct": False,
                "feedback": "Incorrect. The size of a library normally is not a limit.",
            },
            {
                "answer": "Once dynamic plots were introduced, libraries \
                    for static plots were already well developed",
                "correct": False,
                "feedback": "Incorrect. While the statement is true, this is \
                    not the reason \
                    why the different types of graphs are not integrated in a \
                    single library.",
            },
        ],
    },
]
display_quiz(content, colors="fdsp")

Windows workaround#

Install an old version of kaleido via pip:

$ conda activate [your_env]
$ pip install kaleido==0.1.0.post1

Some background:

  • Comment by former plotly employee:

    We do have this unfortunate situation where some (mostly Windows?) users have hanging calls which no one has gotten to the bottom of just yet, though. I don’t know that anyone is actively working on that issue, given the complexity of building the project, but it seems to impact only a small minority of users.

  • Feel free to add your experience to this issue