Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Boxplot resets x-axis limits and ticks #2921

Closed
Milestone
@breedlun

Description

@breedlun

Boxplot appears to reset the x-axis limits and ticks. For example, the following code

import matplotlib.pyplot as pltimport numpy as npfig = plt.figure()ax = plt.subplot()ax.set_xlim(0, 4)ax.set_xticks([0, 0.5, 1, 2, 3.5, 4])ax.set_xticklabels(['a','b','c', '2', '3.5', '4']) ax.set_ylim(0, 8)ax.set_yticks([0, 0.5, 1, 2, 3.5, 4, 8])plt.savefig('before_boxplot.png')

produces this plot
before_boxplot
But when I execute this code next

y1 = np.random.normal(10, 3, 20)y2 = np.random.normal(3, 1, 20)ax.boxplot([y1, y2], positions = [1,2])plt.savefig('after_boxplot.png')

the plot changes to
after_boxplot
Three things changed:

  1. The x-axis limits used to be 0 to 4. They are now roughly 0.5 to 2.5.
  2. The tick marks used to be at [0, 0.5, 1, 2, 3.5, 4]. They are now at [1, 2].
  3. The tick mark labels used to be ['a','b','c', '2', '3.5', '4']. They are now ['a', 'b']. Based on the changes in (1) and (2) I would have expected the tick mark labels to be ['c', '2'].

The obvious work around is to set these parameters after you have calledaxes.boxplot(). However, reseting the axes is not consistent withaxes.plot(),axes.bar(),axes.imshow(), or any other plotting method I have used. Other methods respect the user specified x limits and tick marks. This behavior also is not consistent with the y-axis behavior in boxplot. Boxplot respected the user specified y limits and tick marks.

I am working with Matplotlib 1.3.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp