Matplotlib绘制散点图与条形图

绘制散点图

# 绘制散点图

from matplotlib import pyplot as plt
from matplotlib import font_manager # C:\Windwos\Fonts\msyh.ttc
my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf") y_3 = [11, 17, 16, 11, 12, 11, 12, 6, 6, 7, 8, 9, 12, 15, 14, 17,
18, 21, 16, 17, 20, 14, 15, 15, 15, 19, 21, 22, 22, 22, 23]
y_10 = [26, 26, 28, 19, 21, 17, 16, 19, 18, 20, 20, 19, 22, 23, 17,
20, 21, 20, 22, 15, 11, 15, 5, 13, 17, 10, 11, 13, 12, 13, 6] x_3 = range(0, 31)
x_10 = range(40, 71) # 这是图形大小
plt.figure(figsize=(20, 8), dpi=80) # 使用scatter绘制散点图
plt.scatter(x_3, y_3, label="3月份")
plt.scatter(x_10, y_10, label="10月份") # 调整X的刻度
_x = list(x_3) + list(x_10)
_xtick_lables = ["3月{0}日".format(i) for i in x_3]
_xtick_lables += ["10月{0}日".format(i) for i in x_10]
plt.xticks(_x[::3], _xtick_lables[::3], fontproperties=my_font, rotation=45) # 添加图例
plt.legend(loc="upper left", prop=my_font) # 添加标题
plt.xlabel("月份", fontproperties=my_font)
plt.ylabel("温度", fontproperties=my_font)
plt.title("3月份与10月份温度对比散点图", fontproperties=my_font) # 展示
plt.show()

绘制条形图

# 绘制条形图

from matplotlib import pyplot as plt
from matplotlib import font_manager # 设置字体
my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf") a = [
"战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5:最后的骑士", "摔跤吧!爸爸", "加勒比海盗5:死无对证", "金刚:骷髅岛", "极限特工:终极回归", "生化危机6:终章", "乘风破浪", "神偷奶爸3", "智取威虎山", "大闹天竺", "金刚狼3:殊死一战", "蜘蛛侠:英雄归来", "悟空传", "银河护卫队2", "情圣", "新木乃伊"
] b = [
56.01, 26.94, 17.53, 16.49, 15.45, 12.96, 11.8, 11.61, 11.28,
11.12, 10.49, 10.3, 8.75, 7.55, 7.32, 6.99, 6.88, 6.86, 6.58, 6.23
] # 调整图形大小
plt.figure(figsize=(16, 6), dpi=90) # 绘制图形
# plt.bar是绘制树状条形图
plt.barh(range(len(a)), b, height=0.4, color="red") # 设置Y轴刻度
plt.yticks(range(len(a)), a, fontproperties=my_font) # 设置网格,para:alpha 透明度
plt.grid(alpha=0.4) # 设置标签
plt.xlabel("票房 单位:亿元", fontproperties=my_font)
plt.ylabel("电影", fontproperties=my_font)
plt.title("电影票房统计", fontproperties=my_font) # 展示
plt.show()

Matplotlib绘制散点图与条形图的更多相关文章

  1. 使用matplotlib绘制散点图

    在matplotlib中使用函数 matplotlib.pyplot.scatter 绘制散点图,matplotlib.pyplot.scatter的函数签名如下: matplotlib.pyplot ...

  2. 2. matplotlib绘制散点图

    与绘制直线图的唯一区别:plt.scatter # coding=utf-8 from matplotlib import pyplot as plt from matplotlib import f ...

  3. Python:matplotlib绘制散点图

    与线型图类似的是,散点图也是一个个点集构成的.但不同之处在于,散点图的各点之间不会按照前后关系以线条连接起来. 用plt.plot画散点图     奇怪,代码和前面的例子差不多,为什么这里显示的却是散 ...

  4. matplotlib绘制散点图

    参考自Matplotlib Python 画图教程 (莫烦Python)(10)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16 ...

  5. 第八章用matplotlib、seaborn、pyecharts绘制散点图

    文章目录 散点图 matplotlib绘制散点图 seaborn绘制散点图 pyecharts绘制散点图 源码地址 本文可以学习到以下内容: matplotlib 中文乱码解决办法 seaborn 中 ...

  6. matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图

    一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...

  7. Matplotlib散点图、条形图、直方图-02

    对比常用统计图 折线图: 特点:能够显示数据的变化趋势,反映事物的变化情况.(变化) 直方图: 特点:绘制连续性的数据,展示一组或者多组数据的分布情况(统计) 条形图: 特点:绘制离散的数据,能够一眼 ...

  8. matplotlib 知识点13:绘制散点图(scatter函数精讲)

    散点图是指在回归分析中,数据点在直角坐标系平面上的分布图,散点图表示因变量随自变量而变化的大致趋势,据此可以选择合适的函数对数据点进行拟合. 用两组数据构成多个坐标点,考察坐标点的分布,判断两变量之间 ...

  9. 3.matplotlib绘制条形图

    plt.bar() # coding=utf-8 from matplotlib import pyplot as plt from matplotlib import font_manager my ...

  10. matplotlib库绘制散点图

    假设通过爬虫你获取到了北京2016年3,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温随时间(天)变化的某种规律? a = [11,17,16,11,12,11,12,6,6 ...

随机推荐

  1. 每天学五分钟 Liunx 1000 | 软件篇:源码安装

    软件安装流程 前面软件篇提到了通过 RPM 和 YUM 在线安装的机制安装软件,除了这两种方式之外还有一种通过源码来安装软件的方式.

  2. spring boot 整合kafka

    本文为博主原创,未经允许不得转载: 1. 引入spring boot kafka依赖 <dependency> <groupId>org.springframework.kaf ...

  3. Maven项目手动配置依赖项

    1.问题 很多时候,我们依靠其本身的识别功能,并不能很好的识别依赖项(尤其是指定版本),且对于一些位于 <\build>不能自动去下载,这时候我们就要去手动配置依赖项 2.解决 2.1 首 ...

  4. 【ARM】重新定义低级库函数,以便能够直接使用 C 库中的高级库函数

    Redefining low-level library functions to enable direct use of high-level library functions in the C ...

  5. Laravel - 修改时间戳

    将 config/app.php文件下将timezone的值改成Asia/Shanghai即可

  6. GraduationProject

    GraduationProject 为了毕设寻找的一些springboot项目资源 后台项目: FEBS-Shiro: https://github.com/wuyouzhuguli/FEBS-Shi ...

  7. linux-目录树

  8. [转帖]oracle ZHS16GBK的数据库导入到字符集为AL32UTF8的数据库(转载+自己经验总结)

    字符集子集向其超集转换是可行的,如此例 ZHS16GBK转换为AL32UTF8. 导出使用的字符集将会记录在导出文件中,当文件导入时,将会检查导出时使用的字符集设置,如果这个字符集不同于导入客户端的N ...

  9. 一键部署Docker中间件简单方法-redis为例

    一键部署Docker中间件简单方法-redis为例 背景 想能够快速部署一些中间件. 写文档虽然可以, 但是总会有人问, 能够一键部署应该最好不过. 下载以及导出镜像 docker pull redi ...

  10. [转帖]Debian9换源(阿里源)(Linux子系统)

    http://www.taodudu.cc/news/show-5410026.html?action=onClick 默认你已经装好Linux子系统. Step 0: 换源核心就是把/etc/apt ...