Skip to content

fill_between() misbehaves with logarithmic X axis #7371

Closed as not planned
Closed as not planned
@zevweiss

Description

@zevweiss

I'm seeing fill_between() drawing polygons incorrectly on a logarithmic X axis.

import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import sys

plt.xscale('log')

xs = np.array([10, 100])
ys = np.array([10, -25])
zeros = np.array([0, 0])

plt.plot(xs, ys)

plt.fill_between(xs, zeros, ys, where=ys > zeros, facecolor='green', interpolate=True)
plt.fill_between(xs, zeros, ys, where=ys < zeros, facecolor='red', interpolate=True)

plt.savefig(sys.argv[1])

If I comment out the plt.xscale('log') line everything comes out as expected:

lin

But with the log axis the fill_between() polygons don't align with the plt.plot(xs, ys) line:

log

(This is with matplotlib 1.5.3, installed via pip.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions