{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotly 简介\n", "\n", "[`plotly.py`](https://github.com/plotly/plotly.py) 库(可参考[简单的中文文档](https://daobook.github.io/plotly-book/tutorial/index.html))是交互式的、开源的绘图库,它支持超过 40 种独特的图表类型,涵盖了广泛的统计、金融、地理、科学和三维用例。\n", "\n", "基于 Plotly JavaScript 库([plotly.js](https://plotly.com/javascript/)),Plotly 允许 Python 用户创建漂亮的基于 web 的交互式可视化,可以在 Jupyter 笔记本中显示,保存为独立的 HTML 文件,或使用 Dash 作为纯 Python 构建的 web 应用程序的一部分。plotly Python 库有时被称为 plotly.py,以区别于 JavaScript 库。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%mkdir build\n", "from plotly import graph_objects as go\n", "\n", "fig = go.Figure(data=go.Bar(y=[2, 3, 1]))\n", "# 保存到 HTML 文件\n", "fig.write_html('build/first_figure.html', auto_open=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "可以直接用于 `go.FigureWidget`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly import graph_objects as go\n", "\n", "fig = go.FigureWidget(data=go.Bar(y=[2, 3, 1]))\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "也可以直接显示:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from plotly import graph_objects as go\n", "\n", "fig = go.Figure(data=go.Bar(y=[2, 3, 1]))\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "cv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "04fbf434835a7c224d4fe1e199a95727edbcbb4dd9b3fe74523b9f2dac676df3" } } }, "nbformat": 4, "nbformat_minor": 2 }