Skip to content

Commit

Permalink
add: saving plot options to getting started page/nb
Browse files Browse the repository at this point in the history
  • Loading branch information
singjc committed Jan 1, 2025
1 parent a14ee83 commit fcf9f7c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/Getting Started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,38 @@
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "3de44f76",
"metadata": {},
"source": [
"#### **Saving the Plot**\n",
"\n",
"If you want to save the plot, you need to set `show_plot=False`, and then use the respective backend's save method.\n",
"\n",
"- For matplotlib, you can use `plt.savefig()`\n",
"\n",
"```python\n",
"p = spectrum_df.plot(kind='spectrum', backend='ms_matplotlib', x='mz', y='intensity', show_plot=False)\n",
"plt.savefig('spectrum.png')\n",
"```\n",
"\n",
"- For bokeh, you can use `output_file` method to save an html file of th iteractive plot. To save a static plot you can use the tool bar in the interactive plot to save the plot as a png. Or you can use the `export_png` method. However, this requires additional dependencies: `pip install selenium geckodriver firefox`.\n",
"\n",
"```python\n",
"from bokeh.io import output_file\n",
"p = spectrum_df.plot(kind='spectrum', backend='ms_bokeh', x='mz', y='intensity', show_plot=False)\n",
"output_file(\"spectrum.html\")\n",
"```\n",
"\n",
"- For plotly, you can use `fig.write_html()` method to save an html file of the interactive plot. To save a static plot you can use the tool bar in the interactive plot to save the plot as a png. Or you can use the `write_image` method. However, this requires additional dependencies: `pip install -U kaleido`.\n",
"\n",
"```python\n",
"p = spectrum_df.plot(kind='spectrum', backend='ms_plotly', x='mz', y='intensity', show_plot=False)\n",
"p.write_html(\"spectrum.html\")\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "9c96688c-0b4a-45d7-a491-72392a749e18",
Expand Down

0 comments on commit fcf9f7c

Please sign in to comment.