Matplotlib水平地剪切hbar中的第一个条形

时间:2017-09-14 02:46:43

标签: python matplotlib

我正在努力理解为什么matplotlib hbar图中的第一个横条正在水平切成两半。该栏上也缺少yaxis标签。知道为什么会这样吗?

这是脚本,附件是输出 Output of attached script

import networkx as nx
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
import neptcon as nc
import sys
import pickle

fp = open("C:\Python27\Internal_reports\\shared.pkl")
shared = pickle.load(fp)

con = None

cur, con = nc.connect()
cur = con.cursor()   
scriptFile = open("C:\Python27\Internal_reports\Ann_report_sql\Den diff.sql", 'r')
script = scriptFile.read()
scriptFile.close()    
cur.execute(script.format(**shared))
items = cur.fetchall()
client, ship, imo, diff = zip(*items)
new_list = []
for item in diff:
    new_list.append(int(item))          
N = len( new_list )
x = range( N )   
n_groups = N
index = np.arange(n_groups)
fig = plt.figure()
f, (ax1) = plt.subplots(1, 1, figsize=(8, N/2), sharex=False)
bar_width = 0.95
opacity = 0.5
G = nx.complete_graph(10)
pos = nx.spring_layout(G)

plt.yticks(index+(bar_width/2), ship, fontsize = 9)
ax1.yaxis.grid(True, which='major', color='0.95',linestyle='-')
ax1.set_ylim(0, N)
ax1.xaxis.set_ticks_position('bottom')
ax1.yaxis.set_ticks_position('right')
ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)
ax1.spines['left'].set_visible(False)
for a,b in zip(index,new_list):
    plt.text(b, a-0.2, str(b))  
    plt.barh(a,b,color=cm.autumn(1.*a/len(x)),edgecolor='white')
if N > 40:
    plt.savefig('{} quan_diff.pdf'.format(shared.get("cl")), format='pdf', bbox_inches='tight')
else:
    plt.savefig('C:\Python27\Internal_reports\plots\\quan_diff.png', bbox_inches='tight')

nc.closeCon()

0 个答案:

没有答案