使用数据地址:链接:https://pan.baidu.com/s/1wXtZRDcM-JKk_dIDRyd_dg?pwd=pyth
提取码:pyth

提取一些数据,用来绘图用

import pandas as pd
reviews = pd.read_csv('fandango_scores.csv')
cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']#取一些列做新的数据,file列是电影名,后面的都是媒体名,媒体给电影评分。
norm_reviews = reviews[cols]#取一些列做新的数据norm_reviews
print(norm_reviews[0:2])
'''FILM  RT_user_norm  Metacritic_user_nom  \
0  Avengers: Age of Ultron (2015)           4.3                 3.55
1               Cinderella (2015)           4.0                 3.75   IMDB_norm  Fandango_Ratingvalue  Fandango_Stars
0       3.90                   4.5             5.0
1       3.55                   4.5             5.0
'''#每个媒体的评分都绘制成一个柱子
import matplotlib.pyplot as plt
from numpy import arange
#The Axes.bar() method has 2 required parameters, left and height.
#We use the left parameter to specify the x coordinates of the left sides of the bar.
#We use the height parameter to specify the height of each bar
num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
print(norm_reviews.loc[0, num_cols])#取第0行的数据来绘图
'''
RT_user_norm             4.3
Metacritic_user_nom     3.55
IMDB_norm                3.9
Fandango_Ratingvalue     4.5
Fandango_Stars           5.0
Name: 0, dtype: object
'''bar_heights = norm_reviews.loc[0, num_cols].values#取第0行,num_cols中列的数值,此数据用来作为条状图的条高
print (bar_heights)#[4.3 3.55 3.9 4.5 5.0]
bar_positions = arange(5) + 0.75#表示的是每个柱子的中间位置距离左边原点的距离
bar_positions = arange(5) + 0.75#表示的是每个柱子的中间位置距离左边原点的距离
print(bar_positions)#[0.75 1.75 2.75 3.75 4.75]
fig, ax = plt.subplots()#subplot函数返回一个figure,一个ax
ax.bar(bar_positions, bar_heights, 0.5)#0.5表示的是柱子的粗细
plt.show()

这种图像过于简洁,增加x、y轴描述,图像标题等,需对ax对象进行操作,每个柱子(条)均可定义名称,需对ax对象使用set_xticklabels函数。

#By default, matplotlib sets the x-axis tick labels to the integer values the bars
#spanned on the x-axis (from 0 to 6). We only need tick labels on the x-axis where the bars are positioned.
#We can use Axes.set_xticks() to change the positions of the ticks to [1, 2, 3, 4, 5]:num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
bar_heights = norm_reviews.loc[0, num_cols].values#取得第0行,num_cols中的数据用来绘图
tick_positions = range(1,6)#1, 2, 3, 4, 5
fig, ax = plt.subplots()
ax.bar(bar_positions, bar_heights, 0.5)#传入条状图参数,条位置、条高、条的粗细
ax.set_xticks(tick_positions)#传入参数tick_positions作为每个条的位置1, 2, 3, 4, 5
ax.set_xticklabels(num_cols, rotation=45)#使用set_xticklabels函数对每个条定义名称,num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars'],rotation为旋转角度。ax.set_xlabel('Rating Source')
ax.set_ylabel('Average Rating')
ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
plt.show()


以上柱形图均为竖立型柱形图,想要画出横着的柱形图,需使用函数barh

import matplotlib.pyplot as plt
from numpy import arange
num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_widths = norm_reviews.loc[0, num_cols].values
bar_positions = arange(5) + 0.75
tick_positions = range(1,6)
fig, ax = plt.subplots()
ax.barh(bar_positions, bar_widths, 0.5)#横着画柱形图,需使用barh函数,而非bar函数ax.set_yticks(tick_positions)
ax.set_yticklabels(num_cols)
ax.set_ylabel('Rating Source')
ax.set_xlabel('Average Rating')
ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
plt.show()

plot(matplotlib.pyplot)绘图(条状图)相关推荐

  1. plot(matplotlib.pyplot)绘图(柱状图)(箱线图)

    使用数据地址:链接:https://pan.baidu.com/s/1wXtZRDcM-JKk_dIDRyd_dg?pwd=pyth 提取码:pyth (电影评分数据) 导入数据 import pan ...

  2. python matplotlib绘制多条折线图

    python matplotlib绘制多条折线图 代码 import matplotlib.pyplot as pltx = [6, 24, 48, 72] y1 = [87, 174, 225, 2 ...

  3. Python — matplotlib.pyplot 绘图模块及常用函数

    目录 1. 基本用法与折线图 pyplot 模块的常用函数 折线图函数: matplotlib.pyplot.plot() 常用 format_string 参数 常用函数 grid () 控制各轴网 ...

  4. Matplotlib.pyplot绘图讲解

    Matplotlib.pyplot绘图讲解 matplotlib是基础绘图包,上手比较简单,本文主要是针对之前已经学过的进行一次温习,后面要转战pycharts,比较粗糙,想看具体的可以参考下面两篇文 ...

  5. 如何利用echarts图表获取条状图点击名称和值

    如何利用echarts图表获取条状图点击名称和值 听语音 | 浏览:1505 | 更新:2017-06-13 10:20 | 标签:软件 1 2 3 4 5 6 7 分步阅读 echarts图表插件工 ...

  6. Flex实现双轴条状图

    1.问题背景 一般的,柱状图能够实现双轴图,可是怎样实现双轴条状图? 2.实现实例 <? xml version="1.0" encoding="utf-8&quo ...

  7. 甘特图(别名:横道图、条状图)的画法

    简介: 甘特图(Gantt chart )又叫横道图.条状图(Bar chart).它是以图示的方式通过活动列表和时间刻度形象地表示出任何特定项目的活动顺序与持续时间.在处理多道批处理系统问题时,有时 ...

  8. python Matplotlib.pyplot 如何绘制三维折线图, 散点图, 线框图, 表面图, 柱状图, 箭头图, 2D转3D图, 文本图, 3D拼图, 网状图, 直方图, 角面片图, 条状图?

    参考文章1: Matplotlib.pyplot 三维绘图 https://www.cnblogs.com/wuwen19940508/p/8638266.html 参考文章2: [python图像处 ...

  9. Python可视化——matplotlib.pyplot绘图的基本参数详解

    目录 1.matplotlib简介 2.图形组成元素的函数用法 2.1. figure():背景颜色 2.2 xlim()和 ylim():设置 x,y 轴的数值显示范围 2.3 xlabel()和 ...

最新文章

  1. 吴恩达:告别大数据,AI需要高质量小数据!
  2. STC89C52 STC89LE52 NRF24L01无线 教程 (一)
  3. SKYLINE UVALive - 4108
  4. 梳子刻字刻什么好_校园石阶上被人刻了1700多个字?!这次网友却说好
  5. 快速排序总结,Python版
  6. Galaxy S5维修难 仅拆屏幕就需一小时
  7. AutoCAD.net: 用于ObjectARX 开发的Visual Studio 智能感知文件
  8. 数据结构与算法之树的遍历
  9. SpringMVC+idea+maven搭建项目
  10. Mysql分页之limit用法与limit优化
  11. java7 rhino,rhino1.7.7.1
  12. Keil使用实战总结
  13. HackerRank笔记 - SQL Server
  14. 复习笔记——物联网通信技术判断
  15. matlab如何打开word文档,matlab操作word
  16. 关于药物|新药|药品市场调研报告(实操资料分享)
  17. Android APP过检安全整改
  18. 安卓开发微信页面设计
  19. 如何让自己像打王者荣耀一样发了疯、拼了命、石乐志的学习?(强烈推荐)
  20. 计算图像每行占用的字节数

热门文章

  1. idea 忽略报错配置
  2. php判断股票是跌停了,跌停k线图形态
  3. 菜鸟笔记#1.暴力破解简单程序
  4. 计算机flash实训体会与收获,实训收获和心得体会300字
  5. 【授之以渔】2014初试407分经验之谈
  6. 授之以渔-运维平台发布模块四(Jenkins Pipeline+Saltstack改造篇)
  7. 成人本科计算机应用基础试题,成人本科-《大学计算机应用基础》期末复习习题及答案...
  8. 数智财资,智慧金融 用友联合工行青海分行举办主题论坛圆满落幕
  9. 自制C语言密码加密代码
  10. 2022年-年度总结报告