python - Matplotlib 2.0 stripes in histogram -


i vertical stripes between bins when creating histogram matplotlib 2.0.2, python2.7, win7,64bit, visible both in pdf , png created. usig pgf latex create pdf use includegraphics in pdflatex document. png created quick check.

this not case in matplotlib 1.5.3. how rid of these white lines separating individual bins?

things tried:

  • switching antialiasing on/off (aa=true/false in hist command)
  • drawing line (ls="-"/ls="none" in hist command)
  • one thing kind of work giving width bins (width=2.3), not work pdf in zoom values.

code produce image

import matplotlib mpl mpl.use('pgf') pgf_with_latex = {                      # setup matplotlib use latex output     "pgf.texsystem": "pdflatex",        # change if using xetex or lautex     "text.usetex": true,                # use latex write text     "font.family": "serif",     "font.serif": [],                   # blank entries should cause plots inherit fonts document     "font.sans-serif": [],     "font.monospace": [],     "axes.labelsize": 10,               # latex default 10pt font.     "font.size": 8,     "legend.fontsize": 7,               # make legend/label fonts little smaller     "xtick.labelsize": 7,     "ytick.labelsize": 7,     "pgf.preamble": [         r"\usepackage[utf8x]{inputenc}",    # use utf8 fonts becasue computer can handle :)         r"\usepackage[t1]{fontenc}",        # plots generated using preamble         r"\usepackage{siunitx}",         r"\declaresiunit[number-unit-product = {}] ",         r"\lsb{lsb}",         ]     } mpl.rcparams.update(pgf_with_latex)  import matplotlib.pyplot pl import numpy np  fig=pl.figure(figsize=(3,2))  ax1 = fig.add_subplot(111) dat=np.random.normal(-120-60,40,200000).astype(int) bins=np.arange(int(np.amin(dat))-.5,127.5,2) ax1.hist(dat, bins = bins, stacked = true) ax1.set_title("\\emph{(a)} minimal example") ax1.set_yscale("log", nonposy="clip") ax1.set_ylim(0.8, 20000) ax1.set_xlim(none, 130) ax1.set_ylabel("frequency") ax1.set_xlabel("data") ax1.set_xticks([-300,-200, -127,0,127]) fig.tight_layout(h_pad=1,w_pad=0.2)  pl.savefig('test.png', bbox_inches='tight',dpi=600) pl.savefig('test.pdf', bbox_inches='tight',dpi=600) 

output of above code:
output of above code

1. not using pgf backend

as @unutbu pointed out in (unfortunately deleted) answer, not using pgf backend produce expected plot.

removing line

mpl.use('pgf') 

will give

enter image description here

2. step function

if reason use of pgf backend cannot avoided, workaround may use step function plot histogram. removing ax1.hist(...) code , replacing with

hist, ex = np.histogram(dat, bins = bins) ax1.fill_between(bins[:-1], hist, lw=0.0, step="post") 

gives

enter image description here


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -