{
"上海": 15260,
"杭州": 12586,
"北京": 13305,
"天津": 9000,
"深圳": 16060,
"广州": 14010,
"西安": 8000,
"重庆": 7800,
"成都": 8500
}
import json
def json_to_dict(filename):
json_file = open(filename, 'r', encoding='utf-8')
return json.loads(json_file.read())
from . import matlot
from matplotlib.pylab import *
from flask import render_template
from io import BytesIO
from .func import json_to_dict, ax
import base64
def json_img(data):
font = {'family': 'SimHei',
'weight': 'bold',
'size': '14'}
rc('font', **font)
rc('axes', unicode_minus=False)
rcParams['savefig.dpi'] = 100
for x, y in data.items():
bar(x, y, align='center')
text(x, y + 100, '%.2f' % y, ha='center', va='bottom', size=10, color="#909299")
img = BytesIO()
savefig(img, format='png')
img.seek(0)
img_base64 = base64.b64encode(img.getvalue()).decode('utf8')
ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
return img_base64
@matlot.route('/')
def fig():
data = json_to_dict('./file/matlot.json')
return render_template('fig.html',img_base64=json_img(data))