Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Logarithmic scale of the y-axis does not work when the range is small #29544

Copy link
Copy link
Closed as not planned
@TomManMaz

Description

@TomManMaz
Issue body actions

Bug summary

I have a decreasing function $y\colon [1,3600] \to \mathbb{R}^+$.
I try to set the logarithmic scale for the y-axis, but if the range of the function is small (i.e., the initial and final value are closeby), then the logarithmic scale does not work and it only prints the linear scale.

Code for reproduction

import random

import matplotlib.pyplot as plt


T = 3600
n = 1000
y_start = 10**4
y_end = 0.9*y_start

random.seed(42)
# Generate n increasing random values between 1 and T
x = [random.randrange(1, T) for _ in range(n)]
x.sort()
# Generate n decreasing random values between y_start and y_end
y = [random.uniform(y_end, y_start) for _ in x]

y.sort(reverse=True)

fig, ax = plt.subplots()
ax.set_yscale('log')
ax.plot(x, y)

plt.savefig('step_function.pdf')

Actual outcome

step_function.pdf

Expected outcome

I expected the logarithmis scale. In this example it happens if you set y_end = 0.2*y_start

step_function.pdf

Additional information

No response

Operating system

Linux debian 6.10.11+bpo-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.10.11-1~bpo12+1 (2024-10-03) x86_64 GNU/Linux

Matplotlib Version

3.10.0

Matplotlib Backend

qtagg

Python version

Python 3.13.0

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.