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

歡迎訪問 生活随笔!

生活随笔

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

python

python二维数据读取对齐_从投影的二维直方图绘制对齐的x,y一维直方图

發布時間:2025/3/20 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python二维数据读取对齐_从投影的二维直方图绘制对齐的x,y一维直方图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我需要生成一個類似于this example中所示的圖像:

不同之處在于,我用numpy的histogram2d生成了一個二維直方圖,并用imshow和gridspec繪制了二維直方圖:

如何將二維直方圖投影到水平和垂直直方圖(或曲線)中,使其看起來像第一幅圖像一樣對齊?在import numpy as np

import matplotlib.pyplot as plt

import matplotlib.gridspec as gridspec

data = # Uploaded to http://pastebin.com/tjLqM9gQ

# Create a meshgrid of coordinates (0,1,...,N) times (0,1,...,N)

y, x = np.mgrid[:len(data[0, :, 0]), :len(data[0, 0, :])]

# duplicating the grids

xcoord, ycoord = np.array([x] * len(data)), np.array([y] * len(data))

# compute histogram with coordinates as x,y

h, xe, ye = np.histogram2d(

xcoord.ravel(), ycoord.ravel(),

bins=[len(data[0, 0, :]), len(data[0, :, 0])],

weights=stars.ravel())

# Projected histograms inx and y

hx, hy = h.sum(axis=0), h.sum(axis=1)

# Define size of figure

fig = plt.figure(figsize=(20, 15))

gs = gridspec.GridSpec(10, 12)

# Define the positions of the subplots.

ax0 = plt.subplot(gs[6:10, 5:9])

axx = plt.subplot(gs[5:6, 5:9])

axy = plt.subplot(gs[6:10, 9:10])

ax0.imshow(h, cmap=plt.cm.viridis, interpolation='nearest',

origin='lower', vmin=0.)

# Remove tick labels

nullfmt = NullFormatter()

axx.xaxis.set_major_formatter(nullfmt)

axx.yaxis.set_major_formatter(nullfmt)

axy.xaxis.set_major_formatter(nullfmt)

axy.yaxis.set_major_formatter(nullfmt)

# Top plot

axx.plot(hx)

axx.set_xlim(ax0.get_xlim())

# Right plot

axy.plot(hy, range(len(hy)))

axy.set_ylim(ax0.get_ylim())

fig.tight_layout()

plt.savefig('del.png')

總結

以上是生活随笔為你收集整理的python二维数据读取对齐_从投影的二维直方图绘制对齐的x,y一维直方图的全部內容,希望文章能夠幫你解決所遇到的問題。

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