Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib fill between

I want to use fill between or whatever necesary to colour instead of plotting points in this figure. Basically substitute the dots by a continuos band of colour. How may I achieve this?

enter image description here

The relevant code is the following (the points can be thought as three sets of experimental data, which more or less they are)

import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
from pylab import figure, show

plt.rc('text', usetex=True)
plt.rc('font', family='serif')

fig = figure()
ax = fig.add_subplot(111)

p1, = ax.plot(x_124,y_124,'o')
p2, = ax.plot(x_125,y_125,'o')
p3, = ax.plot(x_126,y_126,'o')

xmax=max(x_124+x_125+x_126)
xmin=min(x_124+x_125+x_126)
ymax=max(y_124+y_125+y_126)
ymin=min(y_124+y_125+y_126)

plt.title('Escenario $m_{h}^{\mathrm{max}}$')

plt.ticklabel_format(style='sci',scilimits=(0,0),axis='both')

ax.xaxis.set_major_locator(MaxNLocator(12))
ax.yaxis.set_major_locator(MaxNLocator(12))
plt.xlim(0.96*xmin,1.04*xmax)
plt.ylim(0.96*ymin,1.04*ymax)

plt.legend(['$m_h$ = 124 GeV','$m_h$ = 125 GeV','$m_h$ = 126 GeV'],numpoints=1,loc=0)

plt.xlabel('M3SQ / GeV')
plt.ylabel('M3SU / GeV')

ax.grid()
show()
like image 565
Jorge Lavín Avatar asked Jul 02 '26 20:07

Jorge Lavín


1 Answers

I know this is an incomplete answer and there should be a more elegant way to do this. But it should work as a quick and dirty method, at least for the top-right corner of your figure.

For each m_h,

  • Go through all the x-values,
  • and look for the highest and lowest y-values for that particular x value (for that m_h).
  • After completing all the x values, you get the 3 lists you need in order to use the fill_between function in matplotlib.

By doing this way, of course, you have to decide how to connect between different "band of continuous colors" such as the red and green at the top right corner.

With the given amount of "dots" in your plot, this method does not work for the set of points in the middle (those that go roughly from y=1.6 to x=1.6 in your figure). This is because you cannot construct a band from a series of one-dimensional dots. You need more samples.

like image 83
Pawin Avatar answered Jul 04 '26 14:07

Pawin