In [4]:
from pyecharts import Bar, Line, Overlap,Grid,Style
#在最后一个初始化中设置svg渲染方式renderer='svg'
#pyecharts_snapshot/main.py 修改 DEFAULT_PIXEL_RATIO 3 or higher
#style = Style( background_color='#010101')
#data
Site_joy=["Amiens Cathedral, France","The Zocalo Plaza, Mexico","Basilica of Our Lady of Guadalupe, Mexico","Grand Bazaar, Turkey","St. Peters Basilica, Vatican City, Italy","Red Square, Russia","Notre Dame Cathedral, France","Moscow Kremlin, Russia","British Museum, UK","Musee Du Louvre, France","The Old City of Jerusalem","Blenheim Palace, UK","Palace of Westminster, UK","Sacre Coeur Basilica, France","Big Ben, UK","Aachen Cathedral, Germany","Colosseum In Rome, Italy","Lotte World, South Korea","Zhuo Zheng Yuan, China","Parthenon, Greece","Archaeological Site of Olympia, Greece","Tower of London, UK","Golden Gate Park, USA","Meiji Jingu Shrine, Japan","Changdeokgung Palace Complex, South Korea","Grand Central Terminal, New York City, USA","Times Square, USA","Forbidden City, China","Pike Place Market, USA","Central Park, USA","Metropolitan Museum of Art, USA","San Agustin Church, Philippines","Arc De Triomphe, France","Cologne Cathedral, Germany","Union Station, USA","Independence Hall, USA","Tsim Sha Tsui, Hong Kong","Bourbon Street, USA","Palace of Versailles, France","Agra Fort, India","Victoria Peak, Hong Kong","Hollywood Walk of Fame, USA","Summer Palace, China","Potala Palace, China","Eiffel Tower, France","Grand Palace, Bangkok, Thailand","Pier 39, USA","Leaning Tower of Pisa, Italy","Faneuil Hall Marketplace, USA","Kronborg Castle, Denmark","Balboa Park, USA","Angkor Wat, Cambodia","Universal Studios, Japan","Disneyland Park, USA","Navy Pier, USA","San Antonio River Walk, USA","Himeji Castle, Japan","Sydney Opera House, Australia","Everland, Gyeonggi-Do, South Korea","Tokyo Disneyland, Japan","Disneyland Park, France","Disneyland Hong Kong, Hong Kong","Las Vegas Strip, USA","Saint Michaels Mount, UK","Disney California Adventure, USA","Niagara Falls, Canada","Islands of Adventure,USA","Universal Studios, Florida, USA","Ocean Park,Hong Kong","Universal Studios,Hollywood, USA","Statue of Liberty, USA","Taj Mahal, India","Disney Holly Wood Studios, USA","Disney Animal Kingdom, USA","Disney Worlds Magic Kingdom, USA","Epcot, USA","Hierapolis Pamukkale, Turkey","Giza Pyramid Complex, Egypt","Stone Henge, UK","Great Wall, China"]
Joy_index=[-0.489017512,-0.415591874,-0.366114286,-0.35534022,-0.343554861,-0.342634473,-0.334333986,-0.327566597,-0.327325643,-0.321063909,-0.318102446,-0.301434168,-0.298237071,-0.297163284,-0.296759391,-0.291366197,-0.289535201,-0.289052301,-0.282133751,-0.26677495,-0.257129577,-0.253468236,-0.243157984,-0.24003943,-0.239103622,-0.224714194,-0.21867018,-0.218661895,-0.204187484,-0.203609485,-0.201912068,-0.196748759,-0.196452819,-0.188603679,-0.184259749,-0.166702669,-0.16535336,-0.159551791,-0.144347887,-0.142962691,-0.133927773,-0.128032213,-0.125498182,-0.115209663,-0.107968428,-0.105367625,-0.101478753,-0.099664171,-0.098212021,-0.097243697,-0.091242823,-0.068925085,-0.064216657,-0.062241042,-0.020917783,-0.010056155,-0.002714506,0.009039348,0.009332359,0.013109237,0.013180215,0.016935892,0.020226876,0.026719101,0.036412692,0.041781404,0.047579685,0.050927249,0.062721075,0.086352976,0.093441842,0.100402745,0.116183924,0.200505363,0.20811355,0.2086688,0.325757991,0.335380831,0.361831426,0.429651905]
Joy_first=[-0.516304348,-0.434210526,-0.434920635,-0.367078374,-0.354691581,-0.354693597,-0.342100762,-0.339866898,-0.33155847,-0.32875895,-0.338486387,-0.362350381,-0.302377748,-0.312950111,-0.30065756,-0.334777898,-0.298414767,-0.334728033,-0.335423197,-0.281911793,-0.326760563,-0.260736596,-0.259401973,-0.250164294,-0.254875314,-0.229620496,-0.22309137,-0.236504623,-0.210724656,-0.212794494,-0.211909757,-0.211163579,-0.208465786,-0.200930429,-0.19143432,-0.177211056,-0.177059595,-0.170169419,-0.167605634,-0.191437309,-0.148415657,-0.140220366,-0.183636364,-0.154968095,-0.119747971,-0.120618332,-0.117090715,-0.124532154,-0.107722904,-0.18487395,-0.11722488,-0.101589103,-0.087864911,-0.111400651,-0.034210925,-0.028419791,-0.057098765,-0.00300918,-0.036062378,-0.002371854,0.000884024,-0.00390625,0.010193552,-0.078651685,0.029018255,0.023333333,0.031520185,0.032968546,0.019683149,0.06221095,0.06376044,0.067300079,0.101899638,0.178363469,0.197695174,0.193768492,0.262557078,0.282442748,0.319458897,0.371781668]
Joy_last=[-0.459541063,-0.396352724,-0.298412698,-0.343004716,-0.332033693,-0.330089511,-0.326441019,-0.31488741,-0.322469766,-0.313179528,-0.298338717,-0.240478781,-0.29384355,-0.281393217,-0.292465969,-0.249187432,-0.280955483,-0.239539749,-0.224660397,-0.251732401,-0.185915493,-0.246358326,-0.225493218,-0.229463308,-0.222667663,-0.219591725,-0.213634071,-0.199323988,-0.197355903,-0.193714098,-0.1924845,-0.181498971,-0.184206123,-0.175216748,-0.176806873,-0.156132173,-0.154202058,-0.149313747,-0.119366197,-0.097247706,-0.118709226,-0.116499403,-0.065454545,-0.072926162,-0.097010581,-0.090246027,-0.085120554,-0.073834638,-0.087890841,-0.004201681,-0.067583732,-0.035187287,-0.039210074,-0.014983713,-0.006518773,0.006848142,0.055555556,0.021064259,0.055555556,0.028594018,0.02538413,0.038143382,0.030026931,0.123595506,0.044164167,0.060701754,0.063108448,0.066694198,0.106096976,0.111442638,0.122020778,0.132752705,0.131766773,0.224639902,0.218676604,0.222510718,0.390410959,0.385920271,0.403746098,0.491246138]
Joy_sub=[0]*80
Joy_0=[0]*80
Site_happiness=["Amiens Cathedral, France","The Zocalo Plaza, Mexico","Basilica of Our Lady of Guadalupe, Mexico","St. Peters Basilica, Vatican City, Italy","Grand Bazaar, Turkey","Archaeological Site of Olympia, Greece","The Old City of Jerusalem","Notre Dame Cathedral, France","Red Square, Russia","Aachen Cathedral, Germany","Musee Du Louvre, France","Moscow Kremlin, Russia","Sacre Coeur Basilica, France","Parthenon, Greece","Colosseum In Rome, Italy","Forbidden City, China","Blenheim Palace, UK","British Museum, UK","Lotte World, South Korea","Palace of Westminster, UK","Big Ben, UK","Meiji Jingu Shrine, Japan","Changdeokgung Palace Complex, South Korea","Kronborg Castle, Denmark","Golden Gate Park, USA","Tower of London, UK","Zhuo Zheng Yuan, China","Pike Place Market, USA","Arc De Triomphe, France","Central Park, USA","Grand Central Terminal, New York City, USA","Metropolitan Museum of Art, USA","Agra Fort, India","San Agustin Church, Philippines","Times Square, USA","Palace of Versailles, France","Cologne Cathedral, Germany","Grand Palace, Bangkok, Thailand","Union Station, USA","Bourbon Street, USA","Leaning Tower of Pisa, Italy","Potala Palace, China","Independence Hall, USA","Tsim Sha Tsui, Hong Kong","Pier 39, USA","Eiffel Tower, France","Balboa Park, USA","Hollywood Walk of Fame, USA","Victoria Peak, Hong Kong","Angkor Wat, Cambodia","Summer Palace, China","Faneuil Hall Marketplace, USA","Disneyland Park, USA","Universal Studios, Japan","Himeji Castle, Japan","Navy Pier, USA","Saint Michaels Mount, UK","Niagara Falls, Canada","San Antonio River Walk, USA","Tokyo Disneyland, Japan","Statue of Liberty, USA","Islands of Adventure,USA","Universal Studios, Florida, USA","Disneyland Hong Kong, Hong Kong","Sydney Opera House, Australia","Ocean Park,Hong Kong","Disney California Adventure, USA","Disneyland Park, France","Las Vegas Strip, USA","Taj Mahal, India","Everland, Gyeonggi-Do, South Korea","Universal Studios,Hollywood, USA","Hierapolis Pamukkale, Turkey","Disney Holly Wood Studios, USA","Disney Worlds Magic Kingdom, USA","Disney Animal Kingdom, USA","Giza Pyramid Complex, Egypt","Epcot, USA","Stone Henge, UK","Great Wall, China"]
Happiness_index=[20.83800429,23.75343012,25.19294731,26.36457958,26.89438589,27.3180124,27.65945057,27.79999907,28.27427739,28.33503402,28.84423082,29.04912022,29.25468997,29.49918756,30.01410531,30.20125425,30.20363712,30.61178736,30.90138462,31.09534083,31.24892207,31.65284173,31.67040622,32.24834517,32.56250768,33.12025966,33.14189536,33.5962419,33.9026127,34.7524968,34.7772116,34.95020537,35.03158223,35.15309827,35.2154588,35.33238279,35.857964,36.01900635,36.41336733,36.48942959,36.65182228,37.15793962,37.30388014,37.61694444,38.51096896,38.54965877,38.64090957,38.69975361,38.82409935,39.03653249,39.75728695,40.01847344,40.84282294,41.56804213,43.09903669,43.78027722,43.86576928,44.2843411,44.3169949,44.66432812,44.8270893,45.372511,45.5547338,45.7739121,45.77409005,45.87278066,46.14544525,46.32914711,46.44707194,46.78431042,47.28509749,48.05632461,48.12114471,50.35525164,52.90102175,53.08020127,53.21545018,53.86142575,61.97059555,63.75913772]
Happiness_first=[19.5798593,22.98838804,22.14489365,25.86491172,26.37561024,24.41889859,26.85704742,27.43268245,27.72848006,26.57810238,28.49776099,28.53706418,28.64092222,28.85382702,29.65208441,29.45853803,27.47718607,30.41834714,29.06849006,30.90286313,31.07761573,31.24203973,31.03043895,28.3852605,31.85779732,32.80016061,30.59328422,33.30714813,33.41603744,34.33773786,34.5663382,34.56431705,32.91584893,34.50380524,35.01950405,34.32119824,35.308558,35.39329452,36.07877462,36.03957149,35.55790456,35.50158387,36.85489639,37.10801906,37.81059338,38.05982957,37.59478932,38.17849484,38.21243558,37.70373496,37.16826273,39.59082231,38.77629577,40.52153263,40.77733102,43.18593097,39.60132584,43.46688877,43.51104622,43.95886322,43.58668486,44.63032051,44.8213937,44.83744072,45.24209268,43.93269419,45.82794762,45.77011555,45.99341738,45.39003457,45.24363548,47.02707116,45.36064954,49.72924827,52.45148298,52.00650475,50.90294402,53.17508925,60.1180359,60.97033368]
Happiness_last=[22.0688439,24.54348442,28.20484444,26.84961529,27.42507837,30.2596169,28.5584302,28.15245468,28.78223911,30.00654009,29.15058819,29.55237164,29.90191129,30.09131708,30.38666093,30.97856815,32.83576823,30.79308104,32.70744404,31.28547182,31.43839207,32.05278483,32.28762153,36.11234454,33.24163132,33.45368845,35.79447753,33.88516869,34.43530647,35.18370587,35.0020864,35.35922143,37.04576086,35.80049606,35.42593218,36.41846884,36.36484703,36.66760037,36.73623645,36.91140974,37.79063015,38.8989959,37.76650284,38.10868493,39.19528127,39.0481517,39.64502901,39.17966706,39.53471045,40.39776334,42.43964909,40.45663231,43.0101785,42.5840591,45.53030633,44.44975416,48.36346348,45.09546956,45.18921897,45.39811484,46.18078081,46.10392702,46.32979125,46.66556652,46.30649964,47.72880269,46.46260885,46.9005726,46.90420966,48.20851122,49.23207749,49.12820125,50.85107078,51.03396102,53.37558191,54.19995173,55.63890161,54.50516925,63.91087253,66.44647992]
Happiness_sub=[0]*80
Happiness_0=[0]*80
def chart(site,value,value_1,value_2,value_3,value_0,min_x=None):
red_bar=[]
white_bar=[]
for i in range(0,len(value_1)):
if(value_2[i]>value_1[i]):
if (value_1[i]<0 and value_2[i]<0):
red_bar.append(value_1[i]-value_2[i])
white_bar.append(value_2[i])
elif (value_1[i]>0 and value_2[i]>0):
red_bar.append(value_2[i]-value_1[i])
white_bar.append(value_1[i])
else:
red_bar.append(value_2[i])
white_bar.append(0)
value_3[i]=value_1[i]
#create
line = Line(background_color='#010101',renderer='svg')
line.add("Joy_index",value, site,
line_width=3,line_color="#FFFF04")
bar = Bar(background_color='#010101',renderer='svg')
#其他参数kwargs要在最后一项中声明,否则加载默认参数
bar.add("0", site, value_0)
bar.add("white", site, white_bar,is_stack=True)
bar.add("red",site,red_bar,is_stack=True)
bar.add("sub",site,value_3,is_stack=True)
bar.add("1", site, value_0,
is_convert=True,is_splitline_show=False,is_legend_show=False,
label_color=['rgba(0,0,0,0)','rgba(0,0,0,0)','#15FFF2','#15FFF2','rgba(0,0,0,0)'],
xaxis_label_textsize=16,xaxis_label_textcolor='#FFFFFF',xaxis_line_color='#FFFFF',xaxis_line_width=1.5,
yaxis_label_textsize=16,yaxis_label_textcolor='#FFFFFF',yaxis_line_color='#FFFFFF',yaxis_line_width=2,
yaxis_interval=0,yaxis_margin=0,xaxis_min=min_x)#-260
overlap = Overlap(width=1000, height=2000)
overlap.add(bar)
overlap.add(line)
return overlap
#style
#overlap.use_theme('dark')
#output
#overlap
#overlap.render(path='Ranking_list.html')
#overlap.render(path='Ranking_list.pdf')
#overlap.render(path='Ranking_list.png')
#overlap.render(path='Ranking_list.svg')
joy_chart=chart(Site_joy,Joy_index,Joy_first,Joy_last,Joy_sub,Joy_0)
happiness_chart=chart(Site_joy,Happiness_index,Happiness_first,Happiness_last,Happiness_sub,Happiness_0)
grid = Grid(width=2800,height=2000)
grid.add(joy_chart, grid_width=1000,grid_left="13%")
grid.add(happiness_chart, grid_width=1000,grid_right="2%")
grid
#grid.render(path='Ranking_list.html')
grid.render(path='Ranking_list.jpeg')
In [59]:
from pyecharts import Bar,Grid,Overlap
attr="Asia,Europe,Africa,Oceania,North America,Urban,Rural,Open space,Closed space,Cultural landscape,Natural landscape,Palace,Religious site,Museum,Amusement,Inexistence,Existence"
Attribute=attr.split(',')
AHI=[0.076878719,-0.38949329,0.198310644,0.100950866,0.233099399,-0.220525327,0.220525327,0.276691472,-0.276691472,-0.054126529,0.276019901,-0.22740983,-0.34010005,-0.086070374,0.463101716,-0.257816831,0.257816831]
Joy=[0.095572298,-0.370388797,0.268490569,0.074080529,0.186849303,-0.307551097,0.307551097,0.252272017,-0.252272017,-0.064686998,0.270783685,-0.164710706,-0.306124975,-0.122296009,0.409361226,-0.210812724,0.210812724]
Tri_tuple=[]
for i in range(0,len(Attribute)):
Tri_tuple.append((Attribute[i],round(AHI[i],2),round(Joy[i],2)))
AHI_rank=sorted(Tri_tuple,key=lambda an_item: an_item[1])
Joy_rank=sorted(Tri_tuple,key=lambda an_item: an_item[2])
data=[{'name':'000','xAxis': -0.4},{'name':'-0.2','xAxis': -0.2},{'name':'0','xAxis': 0},{'name':'0.2','xAxis': 0.2},{'name':'0.4','xAxis': 0.4},{'name':'0.6','xAxis': 0.6}]
def chart(rank,index):
attr_=[i[0] for i in rank]
value_=[i[index] for i in rank]
value_posi=[]
value_nega=[]
for i in value_:
if i >0:
value_posi.append(i)
value_nega.append(0)
else:
value_posi.append(0)
value_nega.append(i)
value_chart=Bar(renderer='svg')
value_chart.add("",attr_,value_posi,is_stack=True,
is_label_show =True,label_pos='right')
value_chart.add("",attr_,value_nega,is_stack=True,
is_convert=True,is_splitline_show=False,
#is_yaxis_show=True,xaxis_type='category',
is_label_show =True,label_pos='left',
mark_line_raw=data)
return value_chart
AHI_chart=chart(AHI_rank,1)
#Joy_chart=chart(Joy_rank,2)
AHI_chart
#AHI_chart.render()
AHI_chart.render(path='chart.svg')