日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 等值线图_python – matplotlib等值线图:对数刻度的比例色度级

發(fā)布時間:2024/7/23 python 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 等值线图_python – matplotlib等值线图:对数刻度的比例色度级 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我建議生成一個偽色條如下(見解釋說明):

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.colors import LogNorm

import matplotlib.gridspec as gridspec

delta = 0.025

x = y = np.arange(0, 3.01, delta)

X, Y = np.meshgrid(x, y)

Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)

Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)

Z = 1e6 * (Z1 * Z2)

fig=plt.figure()

#

# define 2 subplots, using gridspec to control the

# width ratios:

#

# note: you have to import matplotlib.gridspec for this

#

gs = gridspec.GridSpec(1, 2,width_ratios=[15,1])

# the 1st subplot

ax1 = plt.subplot(gs[0])

lvls = np.logspace(0,4,20)

CF = ax1.contourf(X,Y,Z,

norm = LogNorm(),

levels = lvls

)

CS = ax1.contour(X,Y,Z,

norm = LogNorm(),

colors = 'k',

levels = lvls

)

#

# the pseudo-colorbar

#

# the 2nd subplot

ax2 = plt.subplot(gs[1])

#

# new levels!

#

# np.logspace gives you logarithmically spaced levels -

# this, however, is not what you want in your colorbar

#

# you want equally spaced labels for each exponential group:

#

levls = np.linspace(1,10,10)

levls = np.concatenate((levls[:-1],np.linspace(10,100,10)))

levls = np.concatenate((levls[:-1],np.linspace(100,1000,10)))

levls = np.concatenate((levls[:-1],np.linspace(1000,10000,10)))

#

# simple x,y setup for a contourf plot to serve as colorbar

#

XC = [np.zeros(len(levls)), np.ones(len(levls))]

YC = [levls, levls]

CM = ax2.contourf(XC,YC,YC, levels=levls, norm = LogNorm())

# log y-scale

ax2.set_yscale('log')

# y-labels on the right

ax2.yaxis.tick_right()

# no x-ticks

ax2.set_xticks([])

plt.show()

這將給你一個這樣的情節(jié):

編輯

或者,在調(diào)用顏色欄時,使用新的級別和間距=“比例”選項:

>替換這行:

lvls = np.logspace(0,4,20)

用這些:

lvls = np.linspace(1,10,5)

lvls = np.concatenate((lvls[:-1],np.linspace(10,100,5)))

lvls = np.concatenate((lvls[:-1],np.linspace(100,1000,5)))

lvls = np.concatenate((lvls[:-1],np.linspace(1000,10000,5)))

>替換這行:

cbar = plt.colorbar(CF, ticks=lvls, format='%.4f')

有了這個:

cbar = plt.colorbar(CF, ticks=lvls, format='%.2f', spacing='proportional')

你會結(jié)束這個情節(jié):

(格式僅更改,因為新的刻度不需要4位小數(shù))

編輯2

如果你想自動生成像我使用的級別,你可以考慮這段代碼:

levels = []

LAST_EXP = 4

N_LEVELS = 5

for E in range(0,LAST_EXP):

levels = np.concatenate((levels[:-1],np.linspace(10**E,10**(E+1),N_LEVELS)))

總結(jié)

以上是生活随笔為你收集整理的python 等值线图_python – matplotlib等值线图:对数刻度的比例色度级的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。