8000 (issue 900): implemented Range.add_plot() and add_table() by alixdamman · Pull Request #926 · larray-project/larray · GitHub
[go: up one dir, main page]

Skip to content

(issue 900): implemented Range.add_plot() and add_table() #926

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tutorial: added section Excel Plot
  • Loading branch information
alixdamman committed May 23, 2022
commit 759547c2f37bdf0699262c2c7e8939a1c6f60522
46 changes: 44 additions & 2 deletions doc/source/tutorial/tutorial_plotting.ipyml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ cells:
%matplotlib inline


- markdown: |
## Python Plot (matplotlib)


- markdown: |
In a Python script, add the following import on top of the script:

Expand Down Expand Up @@ -145,12 +149,50 @@ cells:
See [pyplot tutorial](https://matplotlib.org/tutorials/introductory/pyplot.html) for a short introduction to `matplotlib.pyplot`.


- markdown: |
## Excel Plot


- markdown: |
It is possible to dump arrays and to make plots in the same time in an Excel workbook:


- markdown: |
```python
# to create a new Excel file, argument overwrite_file must be set to True
with open_excel('workbook_with_plots.xlsx', overwrite_file=True) as wb:
# ---- dump data
# add a new sheet 'BFG' and dump the data for Belgium in it
wb['BFG'] = population['Belgium'].dump()
# store the BFG sheet in a local variable
sh = wb['BFG']
# dump the data for France using the equivalent method add_table()
sh['A18'].add_table(population['France'])
# dump the data for Germany
sh['A35'].add_table(population['Germany'])

# ---- use data to create plots
# basic plot anchored to cell H1 using data for Belgium
sh['H1'].add_plot('A1', title='Belgium population')
# basic plot anchored to cell H18 using data for the France for years 2013 to 2016
sh['H18'].add_plot('A18:E20', title='France population')
# plot with options anchored to cell H35 using data for Germany
sh["H35"].add_plot("A35", title="Germany population", width=500, height=300,
xticks_spacing=2, min_y=40_000_000, max_y=41_500_000)

# actually write data and plots in the Workbook
wb.save()

# the Workbook is automatically closed when getting out the block defined by the with statement
```


# The lines below here may be deleted if you do not need them.
# ---------------------------------------------------------------------------
metadata:
celltoolbar: Edit Metadata
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
language_info:
Expand All @@ -162,7 +204,7 @@ metadata:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.7.3
version: 3.9.5
livereveal:
autolaunch: false
scroll: true
Expand Down
58 changes: 56 additions & 2 deletions doc/source/tutorial/tutorial_plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python Plot (matplotlib)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -246,12 +253,59 @@
"\n",
"See [pyplot tutorial](https://matplotlib.org/tutorials/introductory/pyplot.html) for a short introduction to `matplotlib.pyplot`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Excel Plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is possible to dump arrays and to make plots in the same time in an Excel workbook:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"# to create a new Excel file, argument overwrite_file must be set to True\n",
"with open_excel('workbook_with_plots.xlsx', overwrite_file=True) as wb:\n",
" # ---- dump data\n",
" # add a new sheet 'BFG' and dump the data for Belgium in it \n",
" wb['BFG'] = population['Belgium'].dump()\n",
" # store the BFG sheet in a local variable\n",
" sh = wb['BFG']\n",
" # dump the data for France using the equivalent method add_table()\n",
" sh['A18'].add_table(population['France'])\n",
" # dump the data for Germany\n",
" sh['A35'].add_table(population['Germany'])\n",
" \n",
" # ---- use data to create plots\n",
" # basic plot anchored to cell H1 using data for Belgium\n",
" sh['H1'].add_plot('A1', title='Belgium population')\n",
" # basic plot anchored to cell H18 using data for the France for years 2013 to 2016\n",
" sh['H18'].add_plot('A18:E20', title='France population')\n",
" # plot with options anchored to cell H35 using data for Germany\n",
" sh[\"H35\"].add_plot(\"A35\", title=\"Germany population\", width=500, height=300, \n",
" xticks_spacing=2, min_y=40_000_000, max_y=41_500_000)\n",
" \n",
" # actually write data and plots in the Workbook\n",
" wb.save()\n",
" \n",
"# the Workbook is automatically closed when getting out the block defined by the with statement\n",
"```"
]
}
],
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -265,7 +319,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.5"
},
"livereveal": {
"autolaunch": false,
Expand Down
0