Skip to content

Histogram missing in Matplotlib 2.1.0 #9628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abcdabcd987 opened this issue Oct 30, 2017 · 2 comments
Closed

Histogram missing in Matplotlib 2.1.0 #9628

abcdabcd987 opened this issue Oct 30, 2017 · 2 comments

Comments

@abcdabcd987
Copy link

Bug report

Bug summary

Histogram missing in Matplotlib 2.1.0. See the following figures, one is from 2.1.0 and the other is from 2.0.2.

Code for reproduction

This code is exactly the same code we are using except the data is changed to random one. I suppose it will be minimal enough?

#!/usr/bin/env python3

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import collections

def plot_figure(distribution):
    percentile = [95, 99]
    percentile_color = 'yg'
    mean_color = 'c'
    bins = 100

    legend_handle = []
    legend_title = []

    fig, (ax0, ax1) = plt.subplots(2, sharex=True)
    fig.subplots_adjust(hspace=0)
    mu, sigma = 100, 15
    xs_downstream = mu + sigma*np.random.randn(10000)
    xs_upstream = mu + sigma*np.random.randn(10000)
    xmin = min(np.min(xs_downstream), np.min(xs_upstream))
    xmax = max(np.max(xs_downstream), np.max(xs_upstream))

    hist0 = ax0.hist(xs_downstream, bins=bins, range=(xmin, xmax), color='red', label='{} workload with Proxy'.format(distribution.capitalize()))
    handles, labels = ax0.get_legend_handles_labels()
    line = ax0.axvline(x=np.mean(xs_downstream), color=mean_color, linewidth=1)
    legend_title.append('Mean')
    legend_handle.append(line)

    for percent, color in zip(percentile, percentile_color):
        line = ax0.axvline(x=xs_downstream[int(percent / 100 * len(xs_downstream))], color=color, linewidth=1)
        legend_title.append('{}th percentile'.format(percent))
        legend_handle.append(line)

    ax0.set_yscale('log')
    legend_title += labels
    legend_handle += handles

    hist1 = ax1.hist(xs_upstream, bins=bins, range=(xmin, xmax), color='blue', label='{} workload without Proxy'.format(distribution.capitalize()))
    handles, labels = ax1.get_legend_handles_labels()
    legend_title += labels
    legend_handle += handles
    ax1.axvline(x=np.mean(xs_upstream), color=mean_color, linewidth=1)

    for percent, color in zip(percentile, percentile_color):
        ax1.axvline(x=xs_upstream[int(percent / 100 * len(xs_upstream))], color=color, linewidth=1)

    ax1.set_yscale('log')
    ax0.legend(legend_handle, legend_title)
    ax1.set_xlabel('latency (ms)')

    fig.savefig('latency-{}.pdf'.format(distribution))

def main():
    plot_figure('zipf')
    plot_figure('uniform')

if __name__ == '__main__':
    main()

Actual outcome

qq20171030-095657 2x

Expected outcome

qq20171030-095722 2x

Works well in 2.0.2.

Matplotlib version

  • Operating system: Both macOS High Sierra and Ubuntu 17.10
  • Matplotlib version: 2.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.6.3
  • Jupyter version (if applicable):
  • Other libraries:

Installed using pip3

Thanks!

@tacaswell tacaswell added this to the v2.1.1 milestone Oct 30, 2017
@tacaswell
Copy link
Member

This is a duplicate of #9288 both of which were fixed by #9477 which will be include in 2.1.1 which will be out 'soon'.

In the mean time passing ax0.set_yscale('log', nonposy='clip') is a functional work around.

@tacaswell
Copy link
Member

Sorry we broke this and thank you for taking the time to report it with clear example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants