python画图的模块_学习python画图模块plotnine:第一步安装

官网链接

知乎介绍的文章

简单介绍

语法类似于R语言的ggplot2包的python画图模块

安装

按照官网教程直接使用pip安装

pip install plotnine

遇到报错

fd42f11947c5

image.png

ERROR: Cannot uninstall 'certifi'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

搜索一番找到说可以在pip命令后加参数--ignore-installed certifi

于是使用命令安装

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple plotnine --ignore-installed certifi

这次安装成功没有报错

python中尝试导入这个模块

from plotnine import *

提示

Bad key animation.mencoder_path in file C:\Users\mingy\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\mpl-data\stylelib\_classic_test.mplstyle, line 509 ('animation.mencoder_path: mencoder')

You probably need to get an updated matplotlibrc file from

https://github.com/matplotlib/matplotlib/blob/v3.3.1/matplotlibrc.template

or from the matplotlib source distribution

搜索了一番,发现有人说可以卸载已经安装的matplotlib然后再重新安装试试

使用pip命令卸载

pip uninstall matplotlib

重新安装命令

python -m pip install -U matplotlib --prefer-binary -i https://pypi.tuna.tsinghua.edu.cn/simple

matplotlib升级到了3.3.1

没有遇到报错

打开python然后再导入plotnine模块

from plotnine import *

这次没有任何提示了

接下来试着运行其中的一个例子

from plotnine import *

from plotnine.data import mtcars

ggplot(mtcars,aes(x='wt',y='mpg',color='factor(gear)'))+geom_point()

fd42f11947c5

image.png

ggplot(mtcars,aes(x='wt',y='mpg',color='factor(gear)'))+geom_point()+facet_wrap('~gear',scales="free")

fd42f11947c5

image.png

保存为pdf文件

(ggplot(mtcars,aes(x='wt',y='mpg',color='factor(gear)'))+geom_point()+facet_wrap('~gear',scales="free")).save("Desktop/p1.pdf")

欢迎大家关注我的公众号

小明的数据分析笔记本

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值