我有一个数据帧(cumulative_diff_df),其中包含空间中像素的值:
X coordinate Y coordinate Cumulative Absolute Difference Direct \
0 2669756.6 1259017.6 904.994102
1 2669756.6 1259017.8 876.358333
2 2669756.6 1259034.8 1082.645719
3 2669756.6 1259035.0 1039.702085
4 2669756.6 1259035.4 1442.291473
... ... ... ...
69887 2669803.6 1259002.8 1483.007732
69888 2669803.6 1259003.2 547.435019
69889 2669803.6 1259003.4 624.091325
69890 2669803.6 1259003.6 470.575287
69891 2669803.6 1259004.8 496.540173
Cumulative Absolute Difference Diffuse
0 84.099907
1 85.462752
2 143.034784
3 98.758423
4 153.982973
... ...
69887 179.913676
69888 74.068084
69889 120.342678
69890 77.374445
69891 106.994752
[69892 rows x 4 columns]
现在我想使用此代码在两个单独的子图中绘制它们在直接和间接辐照度方面的差异:
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib_scalebar.scalebar import ScaleBar
# Get the current color limits
direct_min = cumulative_diff_df['Cumulative Absolute Difference Direct'].min()
print(direct_min)
direct_max = cumulative_diff_df['Cumulative Absolute Difference Direct'].max()
print(direct_max)
# First subplot for direct irradiance
plt.subplot(1, 2, 1)
plt.scatter(cumulative_diff_df['X coordinate'], cumulative_diff_df['Y coordinate'], s=100, c=cumulative_diff_df['Cumulative Absolute Difference Direct'],cmap='YlGnBu_r',vmin=direct_min, vmax=direct_max)
plt.scatter(top_10_direct_pixels['X coordinate'], top_10_direct_pixels['Y coordinate'], color='red', marker='x', s=100, label='Top 10 Direct pixels')
plt.title('Daily Difference Direct Irradiance', fontsize=13)
cbar = plt.colorbar(label='Direct Irradiance difference [$Wh/m^2$]', norm=None)
# Set the color limits for the color bar
cbar.set_clim(vmin=direct_min, vmax=direct_max)
cbar.ax.tick_params(labelsize=15) # Increase the size of colorbar ticks and labeling
cbar.set_label('Direct Irradiance difference [$Wh/m^2$]', fontsize=15)
# Omit X and Y axis labels
plt.xticks([])
plt.yticks([])
scale=1
# Add scale bar
scalebar = ScaleBar(scale, location='lower right') # Adjust location as needed
plt.gca().add_artist(scalebar)
plt.legend()
一切都按预期工作,但颜色条在 0 和 1 之间标准化,而不是您在数据框中看到的差值。 我已经尝试过使用 clim 获取颜色条,尝试使用 vmin, vmax 获取数据,但似乎没有任何效果。 有人知道这里出了什么问题吗? 非常感谢你的帮助! :)
感谢@JohanC的回答,我可以按如下方式解决:
# Plotting
plt.figure(figsize=(15, 8))
# Get the current color limits
direct_min = cumulative_diff_df['Cumulative Absolute Difference Direct'].min()
print(direct_min)
direct_max = cumulative_diff_df['Cumulative Absolute Difference Direct'].max()
print(direct_max)
# First subplot for direct irradiance
plt.subplot(1, 2, 1)
l1= plt.scatter(cumulative_diff_df['X coordinate'], cumulative_diff_df['Y coordinate'], s=pixel_size, c=cumulative_diff_df['Cumulative Absolute Difference Direct'],cmap='YlGnBu_r',vmin=direct_min, vmax=direct_max)
plt.scatter(cumulative_diff_df['X coordinate'], cumulative_diff_df['Y coordinate'], s=pixel_size, c=cumulative_diff_df['Cumulative Absolute Difference Direct'],cmap='YlGnBu_r',vmin=direct_min, vmax=direct_max)
plt.scatter(top_10_direct_pixels['X coordinate'], top_10_direct_pixels['Y coordinate'], color='red', marker='x', s=100, label='Top 10 Direct pixels')
plt.title('Daily Difference Direct Irradiance', fontsize=13)
cbar = plt.colorbar(l1,label='Direct Irradiance difference [$Wh/m^2$]')