# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from scipy import optimize plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号 ax = plt.gca()
#去掉边框
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
#移位置 设为原点相交
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0)) # 数据
mu = 100 # mean of distribution
sigma = 15 # standard deviation of distribution
x = mu + sigma * np.random.randn(10000) percentage = 0.95
num_bins = 20
cnt = plt.hist(x, num_bins, normed=1, facecolor='blue', alpha=0.5, cumulative=True)
x = []
y = []
for index in range(len(cnt[1])):
if index != 0:
x.append(cnt[1][index])
for index in range(len(cnt[0])):
y.append(cnt[0][index])
plt.plot(x, y, "red")
x_per = []
y_per = []
for index in range(len(y)):
if y[index] > 0.95:
y_per.append(y[index-1])
y_per.append(y[index])
x_per.append(x[index-1])
x_per.append(x[index])
break
a = (y_per[1]-y_per[0])/(x_per[1]-x_per[0])
b = y_per[1]-a*x_per[1]
y_label = percentage
x_label = (y_label-b)/a
print(x_label)
print(y_label)
x1 = np.linspace(0, x_label, 50)
y1 = x1*0+percentage
plt.plot(x1, y1, "r--")
plt.xlabel('品位')
plt.ylabel('累计频率')
plt.title(r'品位频率累积分布直方图')
# Tweak spacing to prevent clipping of ylabel
plt.show()

效果如下:

关键代码如下:

ax = plt.gca()
#去掉边框
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
#移位置 设为原点相交
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))

python plt画图横纵坐标0点重合的更多相关文章

  1. Python基础-画图:matplotlib

    Python画图主要用到matplotlib这个库.具体来说是pylab和pyplot这两个子库.这两个库可以满足基本的画图需求. pylab神器:pylab.rcParams.update(para ...

  2. Python科学画图小结

    Python画图主要用到matplotlib这个库.具体来说是pylab和pyplot这两个子库.这两个库可以满足基本的画图需求,而条形图,散点图等特殊图,下面再单独具体介绍. 首先给出pylab神器 ...

  3. python数据分析画图体验

    对于numpy的函数,pands等,不是很熟,我来copy一下code,敲击一下,找找感觉. 默认的导入包import numpy as npimport matplotlib.pyplot as p ...

  4. SA:利用SA算法解决TSP(数据是14个虚拟城市的横纵坐标)问题——Jason niu

    %SA:利用SA算法解决TSP(数据是14个虚拟城市的横纵坐标)问题——Jason niu X = [16.4700 96.1000 16.4700 94.4400 20.0900 92.5400 2 ...

  5. python seaborn 画图

    python seaborn 画图 59888745@qq.com 2017.08.02 distplot( )  kdeplot( ) distplot( )为hist加强版, kdeplot( ) ...

  6. python 怎么画图

    1 安装matplotlib: 安装方法:http://www.2cto.com/os/201309/246928.html(其中,安装过程中,tar解压怎么解都有问题.然后就删掉再下载一遍) 2 使 ...

  7. sql 分组统计查询并横纵坐标转换

    关于sql 分组统计查询,我们在做报表的时候经常需要用到;今天就在这里整理下; 先附上一段sql代码: if object_id(N'#mytb',N'U') is not null drop tab ...

  8. Python黑帽编程 2.0 第二章概述

    Python黑帽编程 2.0 第二章概述 于 20世纪80年代末,Guido van Rossum发明了Python,初衷据说是为了打发圣诞节的无趣,1991年首次发布,是ABC语言的继承,同时也是一 ...

  9. Python黑帽编程 4.0 网络互连层攻击概述

    Python黑帽编程 4.0 网络互连层攻击概述 是时候重新温习下下面这张图了. 图2 本章的内容核心包含上图中的网络层和传输层.TCP/IP是整个网络协议体系中的核心,因为从这里开始,数据传输从局域 ...

随机推荐

  1. Asp.Net Core Grpc 入门实践

    Grpc简介 gRPC 是一种与语言无关的高性能远程过程调用 (RPC) 框架. 在 gRPC 中,客户端应用程序可以直接调用不同计算机上的服务器应用程序上的方法,就像它是本地对象一样,从而更轻松地创 ...

  2. SVG path d Attribute

    Scalable Vector Graphics (SVG) 1.1 (Second Edition) W3C Recommendation 16 August 2011 http://www.w3. ...

  3. cnblogs 日期错乱 bug

    cnblogs 日期错乱 bug 时间错乱 bug archive/2004/01/13/ 什么鬼 呀默认时间戳 https://www.cnblogs.com/xgqfrms/archive/200 ...

  4. 如何实现一个 markdown 图片粘贴上传的博客后台系统

    如何实现一个 markdown 图片粘贴上传的博客后台系统 js 实现 drag & drop / copy & paste image uploader MongoDB 设计文档对象 ...

  5. js & regex & var & highlight

    js & regex & var & highlight let key = `ali`.toLocaleUpperCase(); let name = "阿里云计算 ...

  6. puppeteer render local HTML template bug

    puppeteer render local HTML template bug ➜ url-to-poster git:(master) ✗ dev ^-v-^ app is running in ...

  7. CORS OPTIONS

    CORS OPTIONS A CORS preflight request is a CORS request that checks to see if the CORS protocol is u ...

  8. 「NGK每日快讯」2021.1.21日NGK公链第79期官方快讯!

  9. 币圈沸腾!SPC空投上线!不要错过!

    币圈最近处于沸腾的时刻,NGK侧链代币SPC已上线钱包,3.0公链NGK生态之SPC空投又来了,NGK的上一个项目BGV投资收益率最高破一千七百倍,NGK官方此次以算力持有者为中心,将发起第二轮福利- ...

  10. django学习-10.django连接mysql数据库和创建数据表

    1.django模型 Django对各种数据库提供了很好的支持,包括:PostgreSQL.MySQL.SQLite.Oracle. Django为这些数据库提供了统一的调用API. 我们可以根据自己 ...