Skip to content
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

automatically set plotly renderers #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 1 addition & 8 deletions assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ Note: In-class exercises will not be graded.
- [How to read a JSON file](https://www.freecodecamp.org/news/python-parse-json-how-to-read-a-json-file/#how-to-parse-and-read-a-json-file-in-python)
{% else -%}
- **PDF export:**

- **Plotly charts/maps not appearing:** Include the [boilerplate](https://whynameitthat.blogspot.com/2013/10/boiler-plate.html) code.

```python
import plotly.io as pio
pio.renderers.default = "notebook_connected+pdf"
```

- **Plotly charts/maps not appearing:** Make sure you've done the [one-time setup](lecture_0.ipynb#id2).
- **500 error:** You may be outputting too much data. Try reducing your output (in the Jupyter sense) to smaller subsets.
{% endif -%}
- **When using `choropleth_mapbox()`, nothing appears on the map:** Make sure:
Expand Down
34 changes: 21 additions & 13 deletions lecture_0.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -593,22 +593,30 @@
"1. Create a notebook{% if id == 'nyu' %}\n",
" 1. Click `New`\n",
" 1. Under `Notebook`, click `Python [conda env:python-public-policy]`\n",
"{% endif -%}\n",
"1. Paste in [the following example](https://plotly.com/python/linear-fits/#linear-fit-trendlines-with-plotly-express)\n",
"1. Press the ▶️ button (or `Control`+`Enter` on your keyboard)\n",
"1. Do some one-time setup, coping in the following code: <!-- https://stackoverflow.com/a/47051758/358804 -->\n",
"\n",
"```python\n",
"{% if id == 'nyu' -%}\n",
"import plotly.io as pio\n",
"pio.renderers.default = \"notebook_connected+pdf\"\n",
" ```python\n",
" from pathlib import Path\n",
"\n",
"{% endif -%}\n",
"import plotly.express as px\n",
" dest = Path(get_ipython().profile_dir.startup_dir) / \"plotly_renderer.py\"\n",
"\n",
" print(dest)\n",
"\n",
" code = \"\"\"\n",
" import plotly.io as pio\n",
"\n",
"df = px.data.tips()\n",
"fig = px.scatter(df, x=\"total_bill\", y=\"tip\", trendline=\"ols\")\n",
"fig.show()\n",
"``` "
" pio.renderers.default = \"notebook_connected+pdf\"\n",
" \"\"\"\n",
"\n",
" with open(dest, \"w\") as f:\n",
" f.write(code)\n",
"\n",
" print(\"Plotly has been set up\")\n",
" ```\n",
"\n",
"{% endif -%}\n",
"1. Paste in [this example](https://plotly.com/python/linear-fits/#linear-fit-trendlines-with-plotly-express)\n",
"1. Press the ▶️ button (or `Control`+`Enter` on your keyboard)"
]
},
{
Expand Down
Loading