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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python画剖面图_如何创建Matplotlib图形与图像和剖面图相匹配?

發布時間:2025/3/21 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python画剖面图_如何创建Matplotlib图形与图像和剖面图相匹配? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我無法使用subplot和gridspec生成布局,同時仍然保留(1)軸的比率和(2)對軸施加的限制。另一種解決方案是手動將軸放置在圖形中,并相應地控制圖形的大小(正如您在OP中所提到的)。盡管這比使用subplot和gridspec需要更多的工作,但是這種方法仍然非常簡單,可以非常強大和靈活地生成復雜的布局,其中需要對邊距和軸的位置進行精確控制。在

下面是一個例子,它展示了如何通過將圖形的大小設置為軸的大小來實現這一點。相反地,它也有可能在一個預定尺寸的圖形中擬合軸。然后使用圖形邊距作為緩沖區來保持軸的縱橫比。在import numpy as np

import matplotlib.pyplot as plt

plt.close('all')

# generate data

# generate grid and test data

x, y = np.linspace(-3, 3, 300), np.linspace(-1, 1, 100)

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

def f(x,y) :

return np.exp(-(x**2/4+y**2)/.2)*np.cos((x**2+y**2)*10)**2

data = f(X,Y)

# 2d image plot with profiles

h, w = data.shape

data_ratio = h / float(w)

# create figure

# - define axes lenght in inches

width_ax0 = 8.

width_ax1 = 2.

height_ax2 = 2.

height_ax0 = width_ax0 * data_ratio

# define margins size in inches

left_margin = 0.65

right_margin = 0.2

bottom_margin = 0.5

top_margin = 0.25

inter_margin = 0.5

# - calculate total figure size in inches

fwidth = left_margin + right_margin + inter_margin + width_ax0 + width_ax1

fheight = bottom_margin + top_margin + inter_margin + height_ax0 + height_ax2

fig = plt.figure(figsize=(fwidth, fheight))

fig.patch.set_facecolor('white')

# create axe

ax0 = fig.add_axes([left_margin / fwidth,

(bottom_margin + inter_margin + height_ax2) / fheight,

width_ax0 / fwidth, height_ax0 / fheight])

ax1 = fig.add_axes([(left_margin + width_ax0 + inter_margin) / fwidth,

(bottom_margin + inter_margin + height_ax2) / fheight,

width_ax1 / fwidth, height_ax0 / fheight])

ax2 = fig.add_axes([left_margin / fwidth, bottom_margin / fheight,

width_ax0 / fwidth, height_ax2 / fheight])

# plot data

bounds = [x.min(),x.max(),y.min(),y.max()]

ax0.imshow(data, cmap='gray', extent = bounds, origin='lower')

ax1.plot(data[:,w/2],Y[:,w/2],'.',data[:,w/2],Y[:,w/2])

ax1.invert_xaxis()

ax2.plot(X[h/2,:], data[h/2,:], '.', X[h/2,:], data[h/2,:])

plt.show(block=False)

fig.savefig('subplot_layout.png')

結果是:

總結

以上是生活随笔為你收集整理的python画剖面图_如何创建Matplotlib图形与图像和剖面图相匹配?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。