Python-Matplotlib(3) 条形图实战
来源:互联网 发布:逆行武侠 知乎 编辑:程序博客网 时间:2024/06/05 09:52
import pandas as pdreviews = pd.read_csv('fandango_scores.csv')cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']norm_reviews = reviews[cols]print(norm_reviews[:1])
import matplotlib.pyplot as pltfrom 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 barnum_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_heights = norm_reviews.ix[0, num_cols].values#print bar_heightsbar_positions = arange(5) + 0.75#print bar_positionsfig, ax = plt.subplots()ax.bar(bar_positions, bar_heights, 0.5)plt.show()
#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.ix[0, num_cols].valuesbar_positions = arange(5) + 0.75tick_positions = range(1,6)fig, ax = plt.subplots()ax.bar(bar_positions, bar_heights, 0.5)ax.set_xticks(tick_positions)ax.set_xticklabels(num_cols, rotation=45)ax.set_xlabel('Rating Source')ax.set_ylabel('Average Rating')ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')plt.show()
import matplotlib.pyplot as pltfrom numpy import arangenum_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_widths = norm_reviews.ix[0, num_cols].valuesbar_positions = arange(5) + 0.75tick_positions = range(1,6)fig, ax = plt.subplots()ax.barh(bar_positions, bar_widths, 0.5)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()
#Let's look at a plot that can help us visualize many points.fig, ax = plt.subplots()ax.scatter(norm_reviews['Fandango_Ratingvalue'], norm_reviews['RT_user_norm'])ax.set_xlabel('Fandango')ax.set_ylabel('Rotten Tomatoes')plt.show()
#Switching Axesfig = plt.figure(figsize=(5,10))ax1 = fig.add_subplot(2,1,1)ax2 = fig.add_subplot(2,1,2)ax1.scatter(norm_reviews['Fandango_Ratingvalue'], norm_reviews['RT_user_norm'])ax1.set_xlabel('Fandango')ax1.set_ylabel('Rotten Tomatoes')ax2.scatter(norm_reviews['RT_user_norm'], norm_reviews['Fandango_Ratingvalue'])ax2.set_xlabel('Rotten Tomatoes')ax2.set_ylabel('Fandango')plt.show()
阅读全文
0 0
- Python-Matplotlib(3) 条形图实战
- matplotlib 画图 条形图
- matplotlib-条形图
- matplotlib绘制条形图
- matplotlib 绘制条形图
- 【Python】Matplotlib画图(八)——条形图
- Matplotlib条形图与散点图
- matplotlib.pyplot.bar()条形图
- Matplotlib绘制点图,条形图和3D图表
- Echarts条形图实战
- Python数据可视化:Matplotlib 直方图、箱线图、条形图、热图、折线图、散点图。。。
- matplotlib(直方图,条形图,饼图,散点图)基础知识
- matplotlib简单四图----条形图,点阵图,盒型图,箱形图
- matplotlib入门教程--1(条形图, 直方图, 盒须图, 饼图)
- python matplotlib 实战安装 初体验
- Python 读取mysql数据绘制条形图
- Python 画 直方图/条形图/柱状图
- 【D3.JS数据可视化实战记录】绘制条形图
- jquery weui实现多tab异步滚动加载更多
- JAVA(0):java环境变量设置
- Java自动装箱、自动拆箱
- Qt Creator 使用笔记
- 在学习前端的路上
- Python-Matplotlib(3) 条形图实战
- Django学习(1):环境搭建
- [剑指offer]面试题37.两个链表中的第一个公共节点
- Windows搭建python开发环境
- linux初学者-系统启动故障篇
- DNS nginx 在架构中的巧用
- 行内元素与块级元素
- 十大Intellij IDEA快捷键
- 深入浅出 消息队列 ActiveMQ