python 可视化包-plotnine
来源:互联网 发布:安装驱动数据无效 编辑:程序博客网 时间:2024/06/13 03:06
plotnine
CSDN的编辑和上传图片体验太差,更多的例子到plot-example里去看。
https://github.com/has2k1/plotnine-examples
安装
- 官网:https://plotnine.readthedocs.io/en/stable/index.html
- github:https://github.com/has2k1/plotnine
- ggplot2官网:http://ggplot2.tidyverse.org/reference/index.html#section-plot-basics
conda install -c conda-forge plotnine
import pandas as pdimport numpy as npfrom plotnine import * from plotnine.data import *mpg.head(2)
基础图形
参考R for Data Science:http://r4ds.had.co.nz/data-visualisation.html 中的Data visualisation
散点图
# R 写法# (ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy)))# plotnine写法(ggplot(mpg,aes('displ','hwy'))+geom_point())
# ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy, color = class))(ggplot(mpg,aes('displ','hwy',color='class'))+geom_point())
#ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy, size = class))(ggplot(mpg,aes('displ','hwy',size='class'))+geom_point())
# 透明度# ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy, alpha = class)))(ggplot(mpg,aes('displ','hwy',alpha='class'))+geom_point())
<ggplot: (143520728433)>
# 不同性状#ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy, shape = class))(ggplot(mpg,aes('displ','hwy',shape='class'))+geom_point())
<ggplot: (143521318874)>
#ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy), color = "blue")(ggplot(mpg,aes('displ','hwy')) +geom_point(color='blue'))
<ggplot: (-9223371893333956145)>
面板图
#ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy)) + # facet_wrap(~ class, nrow = 2)(ggplot(mpg,aes('displ','hwy')) +geom_point() +facet_wrap('~ class', nrow = 2))
<ggplot: (-9223371893333857329)>
#ggplot(data = mpg) + # geom_point(mapping = aes(x = displ, y = hwy)) + # facet_grid(drv ~ cyl)(ggplot(mpg,aes('displ','hwy')) +geom_point() +facet_wrap('~ drv + cyl'))
<ggplot: (-9223371893334132974)>
拟合曲线
还有一些问题
#ggplot(data = mpg) + # geom_smooth(mapping = aes(x = displ, y = hwy))(ggplot(mpg,aes('displ','hwy')) +geom_point() +geom_smooth(mapping=aes('displ','hwy')))
D:\Anaconda3\lib\site-packages\plotnine\stats\smoothers.py:150: UserWarning: Confidence intervals are not yet implementedfor lowess smoothings. warnings.warn("Confidence intervals are not yet implemented"
<ggplot: (143520360694)>
柱状图
#ggplot(data = diamonds) + # geom_bar(mapping = aes(x = cut))(ggplot(mpg) +geom_bar(mapping=aes('displ')))
<ggplot: (-9223371893334758340)>
(ggplot(mpg) +stat_count(mapping=aes('displ')))
<ggplot: (143521000803)>
(ggplot(data = mpg) + geom_bar(mapping = aes('displ', fill = 'class'),position='fill'))
D:\Anaconda3\lib\site-packages\plotnine\positions\position.py:194: UserWarning: position_fill requires non-overlapping x intervals warn(msg.format(cls.__name__))
<ggplot: (-9223371893334407676)>
(ggplot(data = mpg) + geom_bar(mapping = aes('displ', fill = 'class'),position='dodge'))
D:\Anaconda3\lib\site-packages\plotnine\positions\position.py:194: UserWarning: position_dodge requires non-overlapping x intervals warn(msg.format(cls.__name__))
<ggplot: (-9223371893333687145)>
(ggplot(mpg) + geom_point(mapping = aes('displ', 'hwy'), position = "jitter"))
<ggplot: (143521035633)>
箱线图
(ggplot(mpg,aes('class','hwy')) + geom_boxplot())
<ggplot: (143521206683)>
#ggplot(data = mpg, mapping = aes(x = class, y = hwy)) + # geom_boxplot() +# coord_flip()(ggplot(mpg,aes('class','hwy')) + geom_boxplot() + coord_flip())
<ggplot: (-9223371893333525721)>
# bar <- ggplot(data = diamonds) + # geom_bar(# mapping = aes(x = cut, fill = cut), # show.legend = FALSE,# width = 1# ) + # theme(aspect.ratio = 1) +# labs(x = NULL, y = NULL)# bar + coord_flip()# bar + coord_polar()(ggplot(mpg) + geom_bar(mapping=aes('class',fill='class')) + coord_flip())
<ggplot: (-9223371893333735999)>
阅读全文
1 0
- python 可视化包-plotnine
- python 可视化包 Bokeh
- python中用matplotlib包进行简单的可视化
- python的另外一个数据可视化包 seaborn
- Python NetworkX/Community包进行网络划分和可视化
- python可视化包pygal的安装(利用pip)
- 深度学习之Python的可视化包 – Matplotlib
- 通过python的matplotlib包将Tensorflow数据进行可视化
- python 可视化
- python可视化
- python 可视化
- python可视化
- java可视化包awt
- seaborn 可视化包
- 使用Python的netCDF4和matplotlib.basemap包进行气象数据的可视化
- Python可视化编程
- PYTHON数据可视化
- PYTHON数据可视化
- HDFS_快照
- 几个常见的交易心理陷阱
- 浅谈angular架构(下)
- 百度地图加载多个标记
- 关于AndroidManifest.xml
- python 可视化包-plotnine
- JS中运用函数证明角谷定理
- VisualSVN:允许修改svn提交日志(pre-revpro-change hook)
- Java线程与线程状态
- 【Tensorflow】tensorflow.contrib.slim 包
- iOS App被拒常见原因
- python的 mysql 操作
- NOIP2017游记及总结
- 机器学习之KNN分类器