Skip to main content
 首页 » 编程设计

python之给定 x 和 y 值时旋转密度网格图 (Python)

2024年10月01日898°冷暖

<分区>

我有一组数据点的网格密度图,当使用 matplotlib 2dhistogram 创建网格轮廓时,生成的颜色图似乎在垂直轴上翻转并旋转了。我不明白为什么会这样,但我已将我的代码放在下面并将附上绘图的图像。

import numpy as np 
from ngtsio import ngtsio 
import math  
from statsmodels import robust 
from numpy import mean, absolute 
from astropy.stats import LombScargle 
import matplotlib.pyplot as plt 
 
gridx = np.linspace(0,frac,21) 
gridy = np.linspace(0,1,21) 
 
grid,_,_ = np.histogram2d(new_phase,binned_flux,bins=[gridx,gridy]) 
 
plt.grid(True) 
plt.pcolormesh(gridx,gridy,grid) 
plt.colorbar() 
 
plt.grid() 
plt.plot(new_phase,binned_flux,'r.',linestyle='None',markersize = markersize) 
plt.ylim(0,1) 
plt.xlim(0,frac) 
plt.xlabel('Phase') 

请注意,frac 是 (0.5,1.0,2.0) 的数组,即在 3 个子图 x 轴中看到的限制,代码依次遍历每个和绘图。

非常感谢!