
封面图片来源:https://www.youtube.com/watch?v=j0wvKWb337A
问题描述:
1.为什么要使用 plotly?
首先,我平常是使用 python + numpy + pandas + matplotlib 这一套工具链来处理、分析我的试验数据的,其中 matplotlib 正是我使用最频繁的绘图工具。
但是,经常使用 matplotlib 也让我发现它的一个不便之处,matplotlib 输出的是 静态的、不支持交互的 图形对象,那比方说,我想知道曲线上某点(异常点)的数值,我需要先确定该值的索引,再根据索引和数据变量(如 numpy.ndarray, DataFrame, list)才能确定某一点的数值,这其实是一个比较麻烦的过程。
而 plotly 它可以输出 支持交互的 图形对象,只需要将鼠标移动到感兴趣的点的位置,我们就可以轻松获得该点的信息,对于分析过程来说,十分便利。
2.安装 plotly
起初,我以为安装 plotly 会和安装其他的python包一样简单,所以我就直接
conda install plotly
我使用的代码开发工具是 Jupyter lab,发现在Jupyter lab里面运行测试代码,输出是一片空白,经过一番搜索,发现在 Jupyter lab下使用 plotly ,需要特别的步骤,参考:
JupyterLab Support (Python 3.5+)plotly.com具体步骤:
# step 1.
$ pip install jupyterlab "ipywidgets>=7.5"
# or conda
$ conda install jupyterlab "ipywidgets=7.5"
# step 2. 安装 nodejs 和 npm
pip install npm
conda install -c conda-forge nodejs
# step 3.
jupyter labextension install jupyterlab-plotly@4.13.0
# step 4.
pip install plotly
3.资源
视频教程:Python数据可视化 - Plotly教程 视频的up讲的很清晰,感谢up
视频教程:Working with Plotly Youtube
知乎文章:给 jupyter lab 安装插件 —— 安装 nodejs 和 npm
CSDN文章:jupyter lab 插件安装及必备插件 这里面提到 matplotlib 好像也有交互功能
拓展阅读:10 Python Data Visualization Libraries for Any Field | Mode
拓展阅读:Python Plotly Tutorial
拓展阅读:4 Ways To Improve Your Plotly Graphs 改善图片
拓展阅读:Taking Another Look at Plotly
拓展阅读:Visualization with Plotly.Express: Comprehensive guide
Github: Plotly 有绘图案例和用来练习的数据,非常好!