Issue
I am plotting a Faceted Grid of heatmaps using matplotlib.pyplot.hist2d
as an argument to the map function of the seaborn.FacetGrid
object, the problem is the color representation of values is not consistent across the different plots.
How to map the color palette values to constant values for all the plots?
def hist2dgrid(x, y, **kwargs):
palette = kwargs.pop('color')
bins_x = np.arange(0,24+1.5,1.5)
bins_y = np.arange(0,36+3,2)
plt.hist2d(x, y, bins = [bins_x, bins_y], cmap = palette, cmin = 0.5)
plt.colorbar(label='count')
g= sns.FacetGrid(data=df_clean,col='start_time_day_name',col_wrap = 3)
g.map(hist2dgrid, 'start_time_hour_decimal', 'avg_trip_speed_kmh',color='viridis_r');
Solution
You should pass to matplotlib.pyplot.hist2d
vmin
and vmax
parameters:
Result on a random dataset, without above parameters:
Result on the same dataset, with above parameters:
plt.hist2d(x, y, bins = [bins_x, bins_y], cmap = palette, cmin = 0.5, vmin = 30, vmax = 40)
Answered By - Zephyr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.