From 7d50d7eea0650eb14e55af6403450d8d8c012b88 Mon Sep 17 00:00:00 2001 From: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:08:45 +0530 Subject: [PATCH] add docs for using display with matplotlib (#1029) --- docs/reference/API/display.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/reference/API/display.md b/docs/reference/API/display.md index 335ed2bf..c19e537d 100644 --- a/docs/reference/API/display.md +++ b/docs/reference/API/display.md @@ -51,3 +51,37 @@ To write compliant code, make sure to specify the target using the `target` para
``` + +#### Using matplotlib with display + +`matplotlib` has two ways of plotting things as mentioned [here](https://matplotlib.org/matplotblog/posts/pyplot-vs-object-oriented-interface/) + +- In case of using the `pyplot` interface, the graph can be shown using `display(plt)`. + +```python +import matplotlib.pyplot as plt +import numpy as np + +# Data for plotting +t = np.arange(0.0, 2.0, 0.01) +s = 1 + np.sin(2 * np.pi * t) +plt.plot(t,s) + +display(plt) +``` + +- In case of using the `object oriented` interface, the graph can be shown using `display(fig)` or `display(plt)` both. + +```python +import matplotlib.pyplot as plt +import numpy as np + +# Data for plotting +t = np.arange(0.0, 2.0, 0.01) +s = 1 + np.sin(2 * np.pi * t) + +fig, ax = plt.subplots() +ax.plot(t, s) + +display(fig) # but even display(plt) would have worked! +```