最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python 作圖實(shí)現(xiàn)坐標(biāo)軸截?cái)?打斷)的效果

 更新時(shí)間:2021年04月16日 11:59:38   作者:Dmoll  
這篇文章主要介紹了Python 作圖實(shí)現(xiàn)坐標(biāo)軸截?cái)?打斷)的效果,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

主題:利用python畫圖實(shí)現(xiàn)坐標(biāo)軸截?cái)嗷虼驍?/p>

關(guān)鍵詞:python, plot, matplotlib, break axes

方法一:

首先介紹一種簡(jiǎn)單快速的方法——調(diào)用包 brokenaxes。

詳細(xì)請(qǐng)點(diǎn)擊參考

import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np
fig = plt.figure(figsize=(5,2))
bax = brokenaxes(xlims=((0, .1), (.4, .7)), ylims=((-1, .7), (.79, 1)), hspace=.05, despine=False)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(10 * x), label='sin')
bax.plot(x, np.cos(10 * x), label='cos')
bax.legend(loc=3)
bax.set_xlabel('time')
bax.set_ylabel('value')

效果如下:

方法二:

拼接法,該種方法代碼更繁瑣,但更有可能滿足個(gè)性化的需求。

請(qǐng)點(diǎn)擊參考鏈接

"""
Broken axis example, where the y-axis will have a portion cut out.
"""
import matplotlib.pyplot as plt
import numpy as np
# 30 points between [0, 0.2) originally made using np.random.rand(30)*.2
pts = np.array([
    0.015, 0.166, 0.133, 0.159, 0.041, 0.024, 0.195, 0.039, 0.161, 0.018,
    0.143, 0.056, 0.125, 0.096, 0.094, 0.051, 0.043, 0.021, 0.138, 0.075,
    0.109, 0.195, 0.050, 0.074, 0.079, 0.155, 0.020, 0.010, 0.061, 0.008])
# Now let's make two outlier points which are far away from everything.
pts[[3, 14]] += .8
# If we were to simply plot pts, we'd lose most of the interesting
# details due to the outliers. So let's 'break' or 'cut-out' the y-axis
# into two portions - use the top (ax) for the outliers, and the bottom
# (ax2) for the details of the majority of our data
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
# plot the same data on both axes
ax.plot(pts)
ax2.plot(pts)
# zoom-in / limit the view to different portions of the data
ax.set_ylim(.78, 1.)  # outliers only
ax2.set_ylim(0, .22)  # most of the data
# hide the spines between ax and ax2
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax.tick_params(labeltop='off')  # don't put tick labels at the top
ax2.xaxis.tick_bottom()
# This looks pretty good, and was fairly painless, but you can get that
# cut-out diagonal lines look with just a bit more work. The important
# thing to know here is that in axes coordinates, which are always
# between 0-1, spine endpoints are at these locations (0,0), (0,1),
# (1,0), and (1,1).  Thus, we just need to put the diagonals in the
# appropriate corners of each of our axes, and so long as we use the
# right transform and disable clipping.
d = .015  # how big to make the diagonal lines in axes coordinates
# arguments to pass to plot, just so we don't keep repeating them
kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
ax.plot((-d, +d), (-d, +d), **kwargs)        # top-left diagonal
ax.plot((1 - d, 1 + d), (-d, +d), **kwargs)  # top-right diagonal
kwargs.update(transform=ax2.transAxes)  # switch to the bottom axes
ax2.plot((-d, +d), (1 - d, 1 + d), **kwargs)  # bottom-left diagonal
ax2.plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs)  # bottom-right diagonal
# What's cool about this is that now if we vary the distance between
# ax and ax2 via f.subplots_adjust(hspace=...) or plt.subplot_tool(),
# the diagonal lines will move accordingly, and stay right at the tips
# of the spines they are 'breaking'
plt.show()

效果如下:

補(bǔ)充:python繪制折線圖--縱坐標(biāo)y軸截?cái)?/strong>

看代碼吧~

# -*- coding: utf-8 -*-
"""
Created on Wed Dec  4 21:50:38 2019
@author: muli
"""
import matplotlib.pyplot as plt
from pylab import *                 
mpl.rcParams['font.sans-serif'] = ['SimHei'] #支持中文
 
names = ["1","2","3","4","5"]  # 刻度值命名
x = [1,2,3,4,5]    # 橫坐標(biāo)
y3= [2,3,1,4,5]    # 縱坐標(biāo)
y4= [4,6,8,5,9]    # 縱坐標(biāo)
y5=[24,27,22,26,28]     # 縱坐標(biāo)
f, (ax3, ax) = plt.subplots(2, 1, sharex=False)  # 繪制兩個(gè)子圖
plt.subplots_adjust(wspace=0,hspace=0.08) # 設(shè)置 子圖間距
ax.plot(x, y3, color='red', marker='o', linestyle='solid',label=u'1')   # 繪制折線
ax.plot(x, y4, color='g', marker='o', linestyle='solid',label=u'2')  # 繪制折線
plt.xticks(x, names, rotation=45) # 刻度值
ax3.xaxis.set_major_locator(plt.NullLocator()) # 刪除坐標(biāo)軸的刻度顯示
ax3.plot(x, y5, color='blue', marker='o', linestyle='solid',label=u'3')  # 繪制折線
ax3.plot(x, y3, color='red', marker='o', linestyle='solid',label=u'1') # 起圖例作用
ax3.plot(x, y4, color='g', marker='o', linestyle='solid',label=u'2') # 起圖例作用
ax3.set_ylim(21, 30) # 設(shè)置縱坐標(biāo)范圍
ax.set_ylim(0, 10)  # 設(shè)置縱坐標(biāo)范圍
ax3.grid(axis='both',linestyle='-.') # 打開網(wǎng)格線
ax.grid(axis='y',linestyle='-.')   # 打開網(wǎng)格線
ax3.legend() # 讓圖例生效
plt.xlabel(u"λ") #X軸標(biāo)簽
plt.ylabel("mAP") #Y軸標(biāo)簽
ax.spines['top'].set_visible(False)    # 邊框控制
ax.spines['bottom'].set_visible(True) # 邊框控制
ax.spines['right'].set_visible(False)  # 邊框控制
ax3.spines['top'].set_visible(False)   # 邊框控制
ax3.spines['bottom'].set_visible(False) # 邊框控制
ax3.spines['right'].set_visible(False)  # 邊框控制
ax.tick_params(labeltop='off')  
# 繪制斷層線
d = 0.01  # 斷層線的大小
kwargs = dict(transform=ax3.transAxes, color='k', clip_on=False)
ax3.plot((-d, +d), (-d, +d), **kwargs)        # top-left diagonal
kwargs.update(transform=ax.transAxes, color='k')  # switch to the bottom axes
ax.plot((-d, +d), (1 - d, 1 + d), **kwargs)  # bottom-left diagonal
plt.show()

結(jié)果如圖所示:

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • python求眾數(shù)問題實(shí)例

    python求眾數(shù)問題實(shí)例

    這篇文章主要介紹了python求眾數(shù)問題實(shí)例,包括文件的讀寫、字典的運(yùn)用及數(shù)值的計(jì)算等技巧,需要的朋友可以參考下
    2014-09-09
  • Python 高效編程技巧分享

    Python 高效編程技巧分享

    工作中經(jīng)常要處理各種各樣的數(shù)據(jù),遇到項(xiàng)目趕進(jìn)度的時(shí)候自己寫函數(shù)容易浪費(fèi)時(shí)間。Python 中有很多內(nèi)置函數(shù)幫你提高工作效率。
    2020-09-09
  • 基于python 微信小程序之獲取已存在模板消息列表

    基于python 微信小程序之獲取已存在模板消息列表

    這篇文章主要介紹了基于python 微信小程序之獲取已存在模板消息列表的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Python中異常類型ValueError使用方法與場(chǎng)景

    Python中異常類型ValueError使用方法與場(chǎng)景

    這篇文章主要介紹了Python中的ValueError異常類型,它在處理不合適的值時(shí)拋出,并提供如何有效使用ValueError的建議,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-01-01
  • Python 第三方日志框架loguru使用

    Python 第三方日志框架loguru使用

    使用Python自帶的logging模塊記錄日志,但是總覺得不夠優(yōu)雅。 Loguru解決了這個(gè)問題,接下來通過本文給大家介紹Python 第三方日志框架loguru使用,感興趣的朋友跟隨小編一起看看吧
    2021-05-05
  • Python 3.x 判斷 dict 是否包含某鍵值的實(shí)例講解

    Python 3.x 判斷 dict 是否包含某鍵值的實(shí)例講解

    今天小編就為大家分享一篇Python 3.x 判斷 dict 是否包含某鍵值的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • django drf框架自帶的路由及最簡(jiǎn)化的視圖

    django drf框架自帶的路由及最簡(jiǎn)化的視圖

    這篇文章主要介紹了django-drf框架自帶的路由以及最簡(jiǎn)化的視圖,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 最新評(píng)論

    教育| 贵州省| 海原县| 泌阳县| 同江市| 靖州| 三明市| 两当县| 朔州市| 克什克腾旗| 清徐县| 云浮市| 抚松县| 图木舒克市| 申扎县| 南开区| 翁牛特旗| 莒南县| 珠海市| 南溪县| 永平县| 红河县| 华池县| 霸州市| 梨树县| 阳城县| 万州区| 区。| 五家渠市| 孝义市| 汉阴县| 湟源县| 吉水县| 大同县| 从化市| 阿勒泰市| 乐昌市| 临泽县| 垦利县| 临西县| 紫金县|