标题:请问如何调整下述代码,能将下面的极坐标柱状图中最外面的圆圈去掉,并把各 ...
只看楼主
zdlspace
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-1-14
 问题点数:0 回复次数:0 
请问如何调整下述代码,能将下面的极坐标柱状图中最外面的圆圈去掉,并把各省份名称放在直方图下方,在直方图上方加入各省份数值
程序代码:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 29 17:56:15 2019
@author: Jie Zhang,微信公众号【EasyShu】,本代码源自《Python数据可视化之美》
"""
import numpy as np
from matplotlib import cm,colors
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure, show, rc
import pandas as pd

plt.rcParams["patch.force_edgecolor"] =True
   
mydata=pd.DataFrame(dict(day=["北京","上海","广东","安徽","河南","江苏","重庆","云南","四川","江西","湖北",
                              "河北","西藏","浙江","黑龙江","吉林","辽宁","天津","新疆","山东","海南","广西",
                              "贵州","宁夏","陕西","青海","福建","内蒙古","甘肃"],      
                      月最低工资标准=[10, 60, 50, 20,10,90,30,10,23,34,50,10, 60, 50, 20,10,90,30,10,23,34,50,40,50,60,70,80,90,100],
                      小时最低工资标准=[20,50, 10, 10,30,60,50,60, 50, 20,10,30, 50, 20, 40,10,40,50,40,90,80,120,34,50,10, 60, 50, 20,10]))
                      
                      

n_row = mydata.shape[0]
n_col= mydata.shape[1]
angle = np.arange(0,2*np.pi,2*np.pi/n_row)
    #绘制的数据
    
cmap=cm.get_cmap('Reds',n_col)
color=[colors.rgb2hex(cmap(i)[:3]) for i in range(cmap.N) ]
    
radius1 = np.array(mydata.月最低工资标准)
radius2 = np.array(mydata.小时最低工资标准)


fig = figure(figsize=(8,8),dpi =90)    
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)

#方法用于设置角度偏离,参数值为弧度值数值
ax.set_theta_offset(np.pi/2)
#当set_theta_direction的参数值为1,'counterclockwise'或者是'anticlockwise'的时候,正方向为逆时针;
#当set_theta_direction的参数值为-1或者是'clockwise'的时候,正方向为顺时针;
ax.set_theta_direction(1)
#方法用于设置极径标签显示位置,参数为标签所要显示在的角度
ax.set_rlabel_position(360)



barwidth1=0.07  
barwidth2=0.07
plt.bar(angle,radius1,width=barwidth2, align="center",color=color[0],edgecolor="k",alpha=1,label="月最低工资标准")
plt.bar(angle+barwidth1,radius2,width=barwidth2,align="center", color=color[1],edgecolor="k",alpha=1,label="小时最低工资标准")
#plt.bar(angle+barwidth1*2,radius3,width=barwidth2,align="center", color=color[2],edgecolor="k",alpha=1,label="Eelin")

plt.legend(loc="center",bbox_to_anchor=(1.2, 0, 0, 1))

plt.ylim(-150,140)
plt.xticks(angle+2*np.pi/n_row/4,labels=mydata.day,size=12)
plt.yticks([],verticalalignment='center',horizontalalignment='left')


ax.grid(False)
#plt.grid(which='major',axis ="x", linestyle='-', linewidth='0.5', color='gray',alpha=0.5)
#plt.grid(which='major',axis ="y", linestyle='-', linewidth='0.5', color='gray',alpha=0.5)

#fig.savefig('径向柱图2.pdf')


搜索更多相关主题的帖子: 直方图 标准 color 工资 center 
2021-01-14 02:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504625-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.135184 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved