Skip to content

book/07_data - Matplotlib.pyplot.show #7

@clasandine

Description

@clasandine

To make the jupyter notebook files more clean and concise, it would be useful to decide whether to use plt.show() or not. Both are done in the ipynb files which leads to extra lines being printed when plt.show is not used. For better consistency, it would be valuable to do one or the other for a single file. For example, /book/07_data/sklearn.ipynb uses plt.show() sporadically. For some figures where it does not use the command, this is what is returned.

Out [43]: <matplotlib.legend.Legend at 0x7fdd83df07c0>

In this same file, another style of showing the plot is used where a ; is placed at the end of the last command before the figure is shown. For example:

In [20]:
for name in iris.target_names:
plt.scatter(X[y == name, 0], X[y == name, 1], label=name)
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
plt.legend();

A semi colon is used at the end of plt.legend which omits the printed out statement from Out [43]. Since this action suppresses the output of a final function, it may be useful to use this when showing plots. Perhaps an introduction to this notation or usage of it more instead of plt.show() would be useful in understanding data representation in jupyter notebook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions