并不完美(我没有很长时间使用它),但是为了让您了解按照您想要的方式定制绘图所需使用的Matplotlib方法,下面有一些代码。在

请注意,要像这样微调绘图,很难将内容和显示分开(您可能需要手动设置刻度标签等,因此如果更改数据,它将不会自动工作)。《经济学人》的绘图人员显然这样做是因为他们似乎把左上角的勾号标签弄错了(280应该是260)。在# -*- coding: utf-8 -*-

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.dates as mdates

import matplotlib.ticker as ticker

from datetime import datetime

# Load in some sample data

bond_yields = np.loadtxt('bond_yields.txt',

converters={0: mdates.strpdate2num('%Y-%m-%d')},

dtype = {'names': ('date', 'bond_yield'),

'formats': (datetime, float)})

bank_deposits = np.loadtxt('bank_deposits.txt',

converters={0: mdates.strpdate2num('%Y-%m-%d')},

dtype = {'names': ('date', 'bank_deposits'),

'formats': (datetime, float)})

# Bond yields line is in light blue, bank deposits line in dark red:

bond_yield_color = (0.424, 0.153, 0.090)

bank_deposits_color = (0.255, 0.627, 0.843)

# Set up a figure, and twin the x-axis so we can have two different y-axes

fig = plt.figure(figsize=(8, 4), frameon=False, facecolor='white')

ax1 = fig.add_subplot(111)

ax2 = ax1.twinx()

# Make sure the gridlines don't end up on top of the plotted data

ax1.set_axisbelow(True)

ax2.set_axisbelow(True)

# The light gray, horizontal gridlines

ax1.yaxis.grid(True, color='0.65', ls='-', lw=1.5, zorder=0)

# Plot the data

l1, = ax1.plot(bank_deposits['date'], bank_deposits['bank_deposits'],

c=bank_deposits_color, lw=3.5)

l2, = ax2.plot(bond_yields['date'], bond_yields['bond_yield'],

c=bond_yield_color, lw=3.5)

# Set the y-tick ranges: chosen so that ax2 labels will match the ax1 gridlines

ax1.set_yticks(range(120,280,20))

ax2.set_yticks(range(0, 40, 5))

# Turn off spines left, top, bottom and right (do it twice because of the twinning)

ax1.spines['left'].set_visible(False)

ax1.spines['right'].set_visible(False)

ax1.spines['top'].set_visible(False)

ax2.spines['left'].set_visible(False)

ax2.spines['right'].set_visible(False)

ax2.spines['top'].set_visible(False)

ax1.spines['bottom'].set_visible(False)

ax2.spines['bottom'].set_visible(False)

# We do want ticks on the bottom x-axis only

ax1.xaxis.set_ticks_position('bottom')

ax2.xaxis.set_ticks_position('bottom')

# Remove ticks from the y-axes

ax1.tick_params(axis='y', length=0)

ax2.tick_params(axis='y', length=0)

# Set tick-labels for the two y-axes in the appropriate colors

for tick_label in ax1.yaxis.get_ticklabels():

tick_label.set_fontsize(12)

tick_label.set_color(bank_deposits_color)

for tick_label in ax2.yaxis.get_ticklabels():

tick_label.set_fontsize(12)

tick_label.set_color(bond_yield_color)

# Set the x-axis tick marks to two-digit years

ax1.xaxis.set_major_locator(mdates.YearLocator())

ax1.xaxis.set_major_formatter(mdates.DateFormatter('%y'))

# Tweak the x-axis tick label sizes

for tick in ax1.xaxis.get_major_ticks():

tick.label.set_fontsize(12)

tick.label.set_horizontalalignment('center')

# Lengthen the bottom x-ticks and set them to dark gray

ax1.tick_params(direction='in', axis='x', length=7, color='0.1')

# Add the line legends as annotations

ax1.annotate(u'private-sector bank deposits, €bn', xy=(0.09, 0.95),

xycoords='figure fraction', size=12, color=bank_deposits_color,

fontstyle='italic')

ax2.annotate(u'ten-year government bond yield, %', xy=(0.6, 0.95),

xycoords='figure fraction', size=12, color=bond_yield_color,

fontstyle='italic')

# Add an annotation at the date of the first bail-out. relpos=(0,0) ensures

# that the label lines up on the right of a vertical line

first_bailout_date = datetime.strptime('2010-05-02', '%Y-%m-%d')

xpos = mdates.date2num(first_bailout_date)

ax1.annotate(u'FIRST BAIL-OUT', xy=(xpos, 120), xytext=(xpos, 250), color='r',

arrowprops=dict(arrowstyle='-', edgecolor='r', ls='dashed',

relpos=(0,0)), fontsize=9, fontstyle='italic')

fig.savefig('fig.png', facecolor=fig.get_facecolor(), edgecolor='none')

经济学建模软件 python_从python创建“经济学人”风格的图形相关推荐

  1. 经济学建模软件 python_零基础,经济学专业,适合自学Python吗?

    xieyao 经济专业,0基础自学python,从事相关工作,但是不是一个成功的案例 不过说是0基础,也不完全算,因为毕竟数据处理多多少少还是做过,如果用过excel基本上对基础的数据结构应该有些感觉 ...

  2. 经济学人风格统计分布图怎样绘制?!一行代码搞定

    公众号后台回复"图书",了解更多号主新书内容 作者:宁俊骐 来源:DataCharm 今天小编给大家推荐一种绘制另类分布图的绘制方法,其可以绘制出经济学人风格的箱线分布统计图.当然 ...

  3. 内部揭秘:《经济学人》图表原来是用这些工具制作的

    文 / 王不留(微信公众号:王不留) Our team often gets asked how we create The Economist's charts-is there one speci ...

  4. python三维建模和cad比较_【3D建模】CAD与3D建模软件:有什么区别?

    当有人问以上问题时,每个论坛上都有数百个答案:我应该选择哪种3D软件?人们总是列出他们使用的3D软件,但要为你所zuo做的项目选择最佳软件其实并不容易. 首先,你需要知道3D软件分为两类:CAD和3D ...

  5. 犀牛建模软件的英文语言包_使用tidytext和textmineR软件包在R中进行主题建模(

    犀牛建模软件的英文语言包 In this article, we will learn to do Topic Model using tidytext and textmineR packages ...

  6. python交互式和文件式_使用Python创建和自动化交互式仪表盘

    python交互式和文件式 In this tutorial, I will be creating an automated, interactive dashboard of Texas COVI ...

  7. python创建类统计属性_轻松创建统计数据的Python包

    python创建类统计属性 介绍 (Introduction) Sometimes you may need a distribution figure for your slide or class ...

  8. 3D建模软件大总结,你都知道哪些?

    我们要面对现实:这世界上有很多3D软件.我们不可能要花时间学习所有的的程序.如果你非要这么做,我只能表示服了.每个3D程序都有其优缺点.要区分程序之间差异所需的大多数技术知识是初学者无法掌握的.所以我 ...

  9. 学游戏建模,怎么能没有几款上手的软件,8款超好用的3D建模软件

    只要有水平,做出好作品,完全没问题? 非也非也. 做出一个好作品,不但要靠自身的技巧水平,选择适合自己的3D建模软件也是一个很重要的因素. 所以小编今天就给大家安利8款好用的3D建模软件.无论你是一个 ...

最新文章

  1. youtube-dl
  2. 论文|记忆网络之Memory Networks
  3. django 三天写个人博客
  4. Java眼中的XML--文件读取--2 应用SAX方式解析XML
  5. java.lang包中的常用类
  6. 【手写系列】写一个迷你版的Tomcat
  7. MCtalk教育快报 | 0813
  8. 【笔记】springboot+spring security登录流程实现
  9. 防删库实用指南 | 只需一步,快速召回被误删的表
  10. 华为鸿蒙用户体验计划怎样关闭,华为用户要注意,手机关闭这3个“默认选项”,还能流畅再用2年...
  11. mysql 数据增量备份_MySQL数据库之mysql全量备份、增量备份实现方法
  12. 深度学习-数学-第一篇-标量,向量,矩阵,张量
  13. 2019 国家网信办启动网络生态治理专项行动 剑指12类违法违规互联网信息
  14. linux 查看防火墙对应的进程,Linux系统防火墙进程查看的实用方法
  15. Java基础教程【第八章:访问修饰符】
  16. 《Head First Servlets JSP》-11-Web应用部署
  17. 03-JVM内存分配机制详解
  18. oracle 终止imp,终止imp/exp和expdp/impdp进程运行的方法
  19. Leco题目:整数反转
  20. 基于单片机的条形码扫描系统设计

热门文章

  1. React中组件间通信的方式
  2. React组件的state和props
  3. 僵尸肖恩黑胶唱片_建立一个非常适合黑胶唱片的DIY放大器套件
  4. opensource项目_Best of Opensource.com:年度最佳20篇文章
  5. 加入docker管理员_如何使系统管理员和开发人员同意Docker
  6. java 怎么链接ndk的库_使用ndk-build链接现有的静态库
  7. 多方法接口回调_浅析接口定义和接口回调
  8. 视觉SLAM笔记(55) 位姿图
  9. mysql log stats_MySQL慢查询之pt-query-digest分析慢查询日志
  10. c语言xuanzeti1,c语言选择题库1