简体   繁体   English

matplotlib:在 x 轴上扩展阴影区域之间填充

[英]matplotlib: fill between expand shaded area on x-axis

I want to expand the shaded area from 4.7 to 5 on the x axis (see "example" yellow colored area).我想在 x 轴上将阴影区域从 4.7 扩展到 5(参见“示例”黄色区域)。 I already figured out how to expand the shaded area on the y axis without an additional point or line.我已经想出了如何在没有额外点或线的情况下扩展 y 轴上的阴影区域。

Example例子

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

v3_x = np.array([1.7, 1.8, 2.5, 3.4, 4, 4.1, 4.7])
v3_y = np.array([14, 9, 5, 3, 2.5, 1.5, 1]) 

# add reference point 
reference_point_x = 5
reference_point_y = 15

plt.plot(v3_x, v3_y, drawstyle='steps-post', label='steps-post')
plt.plot(v3_x, v3_y, 'o', color='grey', alpha=0.3)
plt.plot(reference_point_x, reference_point_y, 'o--', color='grey', alpha=0.3)

plt.fill_between(v3_x, v3_y, reference_point_y , step="post", alpha=0.4)

plt.show()

I appreciate every hint.我感谢每一个提示。

You can add a virtual point with numpy.r_ :您可以使用numpy.r_添加虚拟点:

plt.fill_between(np.r_[v3_x, 5], np.r_[v3_y, 0],
                 reference_point_y , step="post", alpha=0.4)

output: output:

在此处输入图像描述

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

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