Is there a way to have a third variable control the color gradient on a log-scaled plot? Also: how would I make a color legend for it? I want it to look something like the image linked below. (https://i.stack.imgur.com/iNkHw.png)
#creating arrays
sulfate = np.array(master['SO4-2_(input)'])
chloride = np.array(master['Cl-_(input)'])
pH = np.array(master['pH'])
#create plot
fig, ax = plt.subplots()
plt.figure(1)
ax.loglog(chloride,sulfate,'.',c=pH,cmap='hsv')
#add 1:1 ratio line
plt.plot( [0,1],[0,1] )
#x and y axes lims
plt.xlim(10.0E-7,10.0E-1)
plt.ylim(10.0E-7,10.0E-1)
plt.show()
When I try to use the technique for a typical scatter plot is says that the variable is not a valid value for color.
As suggested in JohanC's comment, use the
scatterfunction and then set the axis scales to logarithmic separately. To get a colorbar, usecolorbar. If you also want the colorbar to have logarithmic scaling (I am not sure if that is what you want), use thenormargument of scatter and provide amatplotlib.colors.LogNorm.Depending on what data format your original variable
masteris in, there might be easier ways to produce this plot. For example, withxarray:Or with
pandas: