简体   繁体   English

Matplotlib 填充之间

[英]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?我怎样才能做到这一点?

在此处输入图片说明

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()

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,对于每个 m_h,

  • Go through all the x-values,遍历所有的 x 值,
  • and look for the highest and lowest y-values for that particular x value (for that m_h).并寻找该特定 x 值(对于那个 m_h)的最高和最低 y 值。
  • After completing all the x values, you get the 3 lists you need in order to use the fill_between function in matplotlib.完成所有 x 值后,您将获得 3 个列表,以便在 matplotlib 中使用 fill_between 函数。

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).对于图中给定数量的“点”,此方法不适用于中间的一组点(图中大致从 y=1.6 到 x=1.6 的点)。 This is because you cannot construct a band from a series of one-dimensional dots.这是因为您无法从一系列一维点构建带。 You need more samples.您需要更多样品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM