Создание графика плотности абсолютной вероятности из разбросанных данных между различными графиками - PullRequest
0 голосов
/ 05 марта 2020

У меня есть шесть панелей двумерного пространства параметров в виде графика рассеяния в виде (x, y) красных точек. Я хотел бы поместить ось х в 7 ячеек одинакового размера 0,3. Затем я хотел бы представить плотность вероятности в виде карты цветов, в которой темнота каждого пикселя должна соответствовать количеству точек в пикселе. Вот что я сделал, чтобы создать такую ​​цветовую карту, используя функцию hist2d. Однако, как вы можете видеть и предвидеть, количество точек не одинаково (скажем, в самых темных пикселях среди всех 7 панелей). Поэтому вместо этого я хотел бы создать двумерную плотность вероятности, при которой темнота пикселя фактически соответствует шкале абсолютный среди всех 7 панелей. Как мне изменить мой сценарий, чтобы добраться до сути?

Спасибо за вашу помощь,

from numpy import *
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator

bins=[7,7]
color_map = mpl.cm.inferno_r
my_range = [[20.3, 22.3], [8, 12]]
tickwidth = 2

relation, (ax14, ax13, ax12, ax11, ax10, ax9, ax8) = plt.subplots(1, 7, sharex=True, sharey=True, figsize=(16,4))

ax8.hist2d(x0, y0, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax8.text(21.1, 11, '$z=0$', fontsize=20)
ax8.set_xlim([xmin, xmax])
ax8.set_ylim([ymin, ymax])
ax8.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax8.set_xscale("linear", nonposx='clip')
ax8.set_yscale("linear", nonposy='clip')
ax8.xaxis.set_tick_params(width=tick_width)
ax8.yaxis.set_tick_params(width=tick_width)
ax8.get_xaxis().tick_bottom()  


ax9.hist2d(x1, y1, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax9.text(21.1, 11, '$z=0.5$', fontsize=20)
ax9.set_xlim([xmin, xmax])
ax9.set_ylim([ymin, ymax])
ax9.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax9.set_xscale("linear", nonposx='clip')
ax9.set_yscale("linear", nonposy='clip')
ax9.xaxis.set_tick_params(width=tick_width)
ax9.yaxis.set_tick_params(width=tick_width)
ax9.get_xaxis().tick_bottom()  


ax10.hist2d(x2, y2, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax10.text(21.1, 11, '$z=1$', fontsize=20)
ax10.set_xlim([xmin, xmax])
ax10.set_ylim([ymin, ymax])
ax10.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax10.set_xscale("linear", nonposx='clip')
ax10.set_yscale("linear", nonposy='clip')
ax10.xaxis.set_tick_params(width=tick_width)
ax10.yaxis.set_tick_params(width=tick_width)
ax10.get_xaxis().tick_bottom()  


ax11.hist2d(x3, y3, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax11.text(21.1, 11, '$z=1.5$', fontsize=20)
ax11.set_xlim([xmin, xmax])
ax11.set_ylim([ymin, ymax])
ax11.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax11.set_xscale("linear", nonposx='clip')
ax11.set_yscale("linear", nonposy='clip')
ax11.xaxis.set_tick_params(width=tick_width)
ax11.yaxis.set_tick_params(width=tick_width)
ax11.get_xaxis().tick_bottom()  


ax12.hist2d(x4, y4, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax12.text(21.1, 11, '$z=2$', fontsize=20)
ax12.set_xlim([xmin, xmax])
ax12.set_ylim([ymin, ymax])
ax12.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax12.set_xscale("linear", nonposx='clip')
ax12.set_yscale("linear", nonposy='clip')
ax12.xaxis.set_tick_params(width=tick_width)
ax12.yaxis.set_tick_params(width=tick_width)
ax12.get_xaxis().tick_bottom()  


ax13.hist2d(x5, y5, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax13.text(21.1, 11, '$z=2.5$', fontsize=20)
ax13.set_xlim([xmin, xmax])
ax13.set_ylim([ymin, ymax])
ax13.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax13.set_xscale("linear", nonposx='clip')
ax13.set_yscale("linear", nonposy='clip')
ax13.xaxis.set_tick_params(width=tick_width)
ax13.yaxis.set_tick_params(width=tick_width)
ax13.get_xaxis().tick_bottom()  


ax14.hist2d(x6, y6, bins=bins, range=my_range, cmap=color_map, weights=None, cmin=None, cmax=None, data=None)

ax14.text(21.1, 11, '$z=3$', fontsize=20)
ax14.set_xlim([xmin, xmax])
ax14.set_ylim([ymin, ymax])
ax14.yaxis.set_major_locator(MaxNLocator(prune='upper')) 
ax14.set_xscale("linear", nonposx='clip')
ax14.set_yscale("linear", nonposy='clip')
ax14.xaxis.set_tick_params(width=tick_width)
ax14.yaxis.set_tick_params(width=tick_width)
ax14.get_xaxis().tick_bottom()  
ax14.get_yaxis().tick_left()



relation.subplots_adjust(top=0.979,bottom=0.107,left=0.067,right=0.990)
plt.setp([a.get_xticklabels() for a in relation.axes[:-1]], visible=True)
relation.tight_layout()
plt.show()

scattered plot 2D-Histogram

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...