python的matplotlib如何畫不同數量級(或者說刻度分段)的橫軸?

時間 2021-10-30 12:12:05

1樓:旅行者

這是你想要的效果麼?下圖裡我把橫軸5-20縮到乙個比較小的範圍裡,0-4和20-24詳細展開畫

import

matplotlib.pyplot

asplt

import

numpy

asnp

# 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 dataf,

(ax,ax2

,ax3)=

plt.

subplots(1

,3,sharey

=True

)# plot the same data on both axesax.

plot

(pts

)ax2

.plot

(pts

)ax3

.plot

(pts

)# zoom-in / limit the view to different portions of the dataax.

set_xlim(0

,5)# outliers only

ax2.

set_xlim(5

,20)# most of the data

ax3.

set_xlim(20

,25)# most of the data

# hide the spines between ax and ax2ax.

spines

['right'].

set_visible

(False

)ax2

.spines

['left'].

set_visible

(False

)ax2

.spines

['right'].

set_visible

(False

)ax3

.spines

['left'].

set_visible

(False)ax

.yaxis

.tick_left

()ax2

.tick_params

(axis

="y"

,left

=False

,right

=False

)# don't put tick labels at the top

ax3.

yaxis

.tick_right

()plt

.show

()plt

.close

()我參考的是這個例子裡的畫法

Broken Axis - Matplotlib 3.1.0 documentation

2樓:cjavapy

Python Matplotlib 簡介

Python Matplotlib 入門教程Python Matplotlib PyplotPython Matplotlib plot 繪圖Python Matplotlib marker 標記Python Matplotlib 線(Line)Python Matplotlib subplot 子圖Python Matplotlib Scatter 散點圖Python Matplotlib bar 條形圖Python Matplotlib 直方圖(Histograms)Python Matplotlib pie 餅圖參考上面文件看看有沒有幫助

python自動化運維的python 開發運維工具 ,主要是哪方面的?

Wayne 大一點的公司,伺服器都上幾百,上千,甚至數萬臺,這種情況下怎樣做自動化運維?用 SHELL 寫指令碼 FOR 迴圈?呵呵,歇了吧,SHELL 也就適合簡單的系統管理工作。到複雜的自動化任務還得要用專門的開發語言。你可能說了,自動化管理有專門的開源軟體 監控也有,直接拿來用下就好了,但是現...

《Python 核心程式設計》和《Python 學習手冊》哪一本更適合零基礎初學者?為什麼?

TRINITY 我想沒有哪本書像learning python一樣前100多頁都沒有講一點python的語法,這本書從python的特點,從執行方式,從PVM 之前的入門教程裡從來沒提到過這玩意 講起,對於每個部分能多詳細就多詳細。其他的python教程大同小異,但是沒有一本能像這本書一樣 Inuy...

尋找python大神!!!python如何多執行緒併發?

tripleha 因為GIL,我的建議是如果你想使用多核跑並行,使用多程序,multiprocessing windows 下的話建議使用它實現的 Pool linux 下的話建議單開 Process 自己弄程序池維護。如果你了解linux下程序和執行緒的本質的話就不會糾結是多程序還是多執行緒了。p...