各类绘图

## 导入包
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns ## 参数设置
#-------------------------01-------------------------
large = 22; med = 16; small = 12
params = {'axes.titlesize': large,
'legend.fontsize': med,
'figure.figsize': (16, 10),
'axes.labelsize': med,
'axes.titlesize': med,
'xtick.labelsize': med,
'ytick.labelsize': med,
'figure.titlesize': large}
plt.rcParams.update(params)
plt.style.use('seaborn-whitegrid')
sns.set_style("white")
# 显示中文
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False ## box
#-------------------------01-------------------------
fig=plt.figure(figsize=(10,6), dpi= 80)
ax1=fig.add_subplot(121)
sns.boxplot(x=personal_df.minutes,ax=ax1)
ax1.set_xlabel('个人客户')
ax1.set_xlim(0,500)
ax1.set_title('空调开启时长分布', fontsize=16, loc='center')
ax1.legend() #-------------------------02-------------------------
fig=plt.figure(figsize=(12,6), dpi= 80)
ax2=fig.add_subplot(121)
sns.boxplot(x='company_type', y='minutes',data = company_df,ax=ax2)
ax2.set_xlabel('公司客户')
ax2.set_title('空调开启时长分布', fontsize=16, loc='center')
ax2.legend() ## bar
#-------------------------01-------------------------
plt.figure(figsize=(10,6),dpi = 72)
ax = sns.barplot(x=p_vehacfanspeed_times_mean_df.index.values, y=p_vehacfanspeed_times_mean_df.times_minutes.values, palette="rocket")
ax.axhline(0, color="k", clip_on=False)
ax.set_ylabel('平均时长/分钟')
ax.set_xlabel('空调风速')
# ax.set_axis_off()
ax.set_title('个人用户', fontsize=24, loc="center", pad=10)
# Annotate Text
for i, cty in enumerate(p_vehacfanspeed_times_mean_df.times_minutes.values):
ax.text(i, cty+0.5, round(cty, 1),fontsize=12, horizontalalignment='center') #-------------------------02-------------------------
otal_width, n = 0.8, 2 # 有多少个类型,只需更改n即可
width = total_width / n # the width of the bars
# x = x - (total_width - width) / 2 fig, ax = plt.subplots(figsize=(10,8),dpi= 80)
rects1 = ax.bar(company_out_freq_count_s.index.values+width, company_out_freq_count_s.values, width,label = '公司客户', color='r')
rects2 = ax.bar(personal_out_freq_count_s.index.values, personal_out_freq_count_s.values, width,label = '个人客户', color='b') def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.02*height,
'%d' % int(height),
ha='center', va='bottom') autolabel(rects1)
autolabel(rects2) ax.set_ylabel('频数')
ax.set_title('个人/公司车辆一天出行次数分布')
plt.legend() ## distplot
#-------------------------01-------------------------
fig=plt.figure(figsize=(16,6), dpi= 80) ax1=fig.add_subplot(121) #1*2的图形 在第一个位置
sns.distplot(company_out_df['delta_time_h'], color="dodgerblue", label="company_out", hist_kws={'alpha':.7}, kde_kws={'linewidth':3},ax=ax1)
sns.distplot(personal_out_df['delta_time_h'], color="orange", label="personal_out", hist_kws={'alpha':.7}, kde_kws={'linewidth':3},ax=ax1)
ax1.set_ylim(0,1)
# Decoration
ax1.set_xlabel("单次出行时长/h")
ax1.set_title('单次出行时长密度分布', fontsize=22)
ax1.legend() ## pie
#-------------------------01-------------------------
fig = plt.figure(figsize=(12, 8), dpi= 80)
def func(pct, allvals):
absolute = int(pct/100.*np.sum(allvals))
return "{:.1f}% ({:d} )".format(pct, absolute) ax1=fig.add_subplot(221)
personal_charge_data = [personal_fcharge_car_nums, personal_scharge_car_nums]
categories = pd.Series(data = ['快充', '慢充'])
explode = [0,0.1]
wedges, texts, autotexts = ax1.pie(personal_charge_data,
autopct=lambda pct: func(pct, personal_charge_data),
textprops=dict(color="w"),
colors=plt.cm.Dark2.colors,
startangle=140,
explode=explode) # ax1.legend(wedges, categories, title="充电类型", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1))
ax1.set_title('个人充电类型占比')

相关资源

帮助文档:

Matplotlib tutorial for beginner: https://github.com/rougier/matplotlib-tutorial

图之典:http://tuzhidian.com/

例子:

effective data visualization

Matplotlib 中文文档

notebook_matplotlib_visualizations.ipynb

top-50-matplotlib-visualizations-the-master-plots-python

art_of_data_visualization: text pre-processing

利用 Matplotlib 绘图的更多相关文章

  1. python中利用matplotlib绘图可视化知识归纳

    python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...

  2. Matplotlib绘图双纵坐标轴设置及控制设置时间格式

    双y轴坐标轴图 今天利用matplotlib绘图,想要完成一个双坐标格式的图. fig=plt.figure(figsize=(20,15)) ax1=fig.add_subplot(111) ax1 ...

  3. matplotlib绘图基本用法-转自(http://blog.csdn.net/mao19931004/article/details/51915016)

    本文转载自http://blog.csdn.net/mao19931004/article/details/51915016 <!DOCTYPE html PUBLIC "-//W3C ...

  4. 【CITE】利用鼠标绘图C#

    实例018 利用鼠标绘图 光盘位置:光盘\MR\01\018 在常用的画图软件中,用户一般都可以通过鼠标在其中绘图,那么该功能是如何实现的呢?本实例将讲解如何使用C#实现通过拖动鼠标在窗体上绘图的功能 ...

  5. 利用WPF绘图

    C#入门经典 25章的一个例子,利用WPF绘图. XAML: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/p ...

  6. matplotlib 绘图

    http://blog.csdn.net/jkhere/article/details/9324823 都打一遍 5 matplotlib-绘制精美的图表 matplotlib 是python最著名的 ...

  7. python实战学习之matplotlib绘图续

    学习完matplotlib绘图可以设置的属性,还需要学习一下除了折线图以外其他类型的图如直方图,条形图,散点图等,matplotlib还支持更多的图,具体细节可以参考官方文档:https://matp ...

  8. matplotlib绘图的基本操作

    转自:Laumians博客园 更简明易懂看Matplotlib Python 画图教程 (莫烦Python)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili. ...

  9. python实战学习之matplotlib绘图

    matplotlib 是最流行的Python底层绘图库,主要做数据可视化图表 可以将数据可视化,能够更直观的呈现数据 matplotlib绘图基本要点 首先实现一个简单的绘图 # 导入pyplot f ...

随机推荐

  1. Bootstrap4 glyphicon 移除图标 glyphicon fonts-faces 解决方案

    bootrap3是支持的图标 ,4不支持 4已经移除了 收费图标,取而代之建议使用其他的,比如 https://octicons.github.com/ 和http://fontawesome.io/ ...

  2. Java 8 New Features

    What's New in JDK 8 https://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html Java Pla ...

  3. Idea中编辑后需要重启问题

    发布的artifact要用exploded 配置On Update action 和On frame deactivation为Update classes and resources. 编辑完成后, ...

  4. Java 初识

    一.Java 简介 1.什么是 Java Java 语言是美国 Sun 公司(Stanford University Network),在1995年推出的高级的编程语言,所谓编程语言,是计算机的语言, ...

  5. Java 数据类型 & 变量与常量 & 注释

    一.数据类型 1.数据类型分类 Java 的数据类型分为两大类: 基本数据类型:整数.浮点数.字符型.布尔型 引用数据类型(对象类型):类.数组,字符串.接口等. 2.基本数据类型 四类八种基本数据类 ...

  6. JavaScript 调试 debug

    一.错误 1.语法错误 出现错误,有提示,很容易的解决. 2.逻辑错误 不容易发现 二.调试方式 1.alert() 方式 2.console.log()/console.error() 方式 3.断 ...

  7. Spring中基于注解的IOC(二):案例与总结

    2.Spring的IOC案例 创建maven项目 导入依赖 pom.xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

  8. JS判断是否是数组的四种做法(转载)

    转载来源 https://www.cnblogs.com/echolun/p/10287616.html 一.前言 如何判断一个对象或一个值是否是一个数组,在面试或工作中我们常常会遇到这个问题,既然出 ...

  9. Oracle ERP 库存管理(业务流程 核心流程)

    库存核心业务 库存管理的核心是对货物本身的管理,是对货物的数量与相关属性的管理,目的是为销售与采购服务,确保合理的库存保有量,处理库存分类帐目与进出流水帐,以单据的形式基本涵盖仓库的各种进出库业务. ...

  10. 简述-selenium对web实现自动化测试

    首先,我是基于python进行对selenium操作和使用的,主要分为selenium的实现原理和selenium的操作这两大部分的简单分享(由于本人水平有限,仅做基础的概述和总结): 一.selen ...