Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
9f1d91df5e
commit
55d9f1bf50
1 changed files with 22 additions and 4 deletions
|
@ -16,6 +16,14 @@ Questions to [David Rotermund](mailto:davrot@uni-bremen.de)
|
||||||
|
|
||||||
If you don't know what I am talking about, please read: [Python Interactive window](https://code.visualstudio.com/docs/python/jupyter-support-py)
|
If you don't know what I am talking about, please read: [Python Interactive window](https://code.visualstudio.com/docs/python/jupyter-support-py)
|
||||||
|
|
||||||
|
## Executing a cell
|
||||||
|
|
||||||
|
In the cell mode (# %%) you can use
|
||||||
|
* SHIFT + ENTER to execute a cell or
|
||||||
|
* CTRL + ENTER.
|
||||||
|
|
||||||
|
The former moves the cursor into the next cell, while the later keeps the cursor that the original position.
|
||||||
|
|
||||||
## [Interactive plotting in # %% cells](https://matplotlib.org/ipympl/)
|
## [Interactive plotting in # %% cells](https://matplotlib.org/ipympl/)
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
@ -32,6 +40,7 @@ The first time we use this command, vs code will need to download a plugin).
|
||||||
Here an example:
|
Here an example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# %%
|
||||||
%matplotlib widget
|
%matplotlib widget
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
@ -49,6 +58,7 @@ Yes, mypy will give you an error and yes, you can not suppress it... but non you
|
||||||
First we plot something but keep the handle:
|
First we plot something but keep the handle:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# %%
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
@ -59,6 +69,7 @@ line = plt.plot(np.sin(np.linspace(0, 20, 100)))
|
||||||
Then we can use to change the plot using the handle:
|
Then we can use to change the plot using the handle:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# %%
|
||||||
line[0].remove()
|
line[0].remove()
|
||||||
line = plt.plot(np.sin(5.0*np.linspace(0, 20, 100)))
|
line = plt.plot(np.sin(5.0*np.linspace(0, 20, 100)))
|
||||||
```
|
```
|
||||||
|
@ -66,6 +77,7 @@ line = plt.plot(np.sin(5.0*np.linspace(0, 20, 100)))
|
||||||
If you don't know the handle, you can retrieve it like this:
|
If you don't know the handle, you can retrieve it like this:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# %%
|
||||||
handles = fig.gca().get_children()
|
handles = fig.gca().get_children()
|
||||||
print(handles)
|
print(handles)
|
||||||
```
|
```
|
||||||
|
@ -74,18 +86,24 @@ print(handles)
|
||||||
[<matplotlib.lines.Line2D object at 0x7fe130f75310>, <matplotlib.spines.Spine object at 0x7fe130f1d710>, <matplotlib.spines.Spine object at 0x7fe130f1dcd0>, <matplotlib.spines.Spine object at 0x7fe130f1e210>, <matplotlib.spines.Spine object at 0x7fe130f1e750>, <matplotlib.axis.XAxis object at 0x7fe130f1ecd0>, <matplotlib.axis.YAxis object at 0x7fe1310b7350>, Text(0.5, 1.0, ''), Text(0.0, 1.0, ''), Text(1.0, 1.0, ''), <matplotlib.patches.Rectangle object at 0x7fe130f3cf10>]
|
[<matplotlib.lines.Line2D object at 0x7fe130f75310>, <matplotlib.spines.Spine object at 0x7fe130f1d710>, <matplotlib.spines.Spine object at 0x7fe130f1dcd0>, <matplotlib.spines.Spine object at 0x7fe130f1e210>, <matplotlib.spines.Spine object at 0x7fe130f1e750>, <matplotlib.axis.XAxis object at 0x7fe130f1ecd0>, <matplotlib.axis.YAxis object at 0x7fe1310b7350>, Text(0.5, 1.0, ''), Text(0.0, 1.0, ''), Text(1.0, 1.0, ''), <matplotlib.patches.Rectangle object at 0x7fe130f3cf10>]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This allows us to do this:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# %%
|
||||||
|
fig.gca().get_children()[0].remove()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-Plotting
|
||||||
|
|
||||||
You can use
|
You can use
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# %%
|
||||||
display(fig)
|
display(fig)
|
||||||
```
|
```
|
||||||
|
|
||||||
for replotting the plot. However you will get a message from VS Code that display is not defined. It is defined but it doesn't know it.
|
for replotting the plot. However you will get a message from VS Code that display is not defined. It is defined but it doesn't know it.
|
||||||
|
|
||||||
|
|
||||||
This allows us to do this:
|
|
||||||
|
|
||||||
```python
|
|
||||||
fig.gca().get_children()[0].remove()
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue