继续增加十二长生的代码,优化布局
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | import matplotlib.pyplot as plt import matplotlib import matplotlib.gridspec as gridspec matplotlib.rcParams[ 'font.family' ] = 'FangSong' from qimen3 import * y = int ( input ( "请输入年份: " )) m = int ( input ( "请输入月份: " )) d = int ( input ( "请输入日期: " )) h = int ( input ( "请输入时间(24小时制):" )) print (Qimen(y,m,d,h).p) jihe = Qimen(y,m,d,h).p gs = gridspec.GridSpec( 3 , 3 ) def paipan(x): plt.xticks([]) plt.yticks([]) global dipan, tianpan, men #天盘干 tianpan = jihe[ '天盤' ][ 0 ][x] plt.text( 0.65 , 0.3 , tianpan) # 天盘十二长生 if x = = '兌' : if tianpan = = '戊' or tianpan = = '丙' : plt.text( 0.8 , 0.3 , '死' , fontsize = 8 , color = 'green' ) if tianpan = = '庚' : plt.text( 0.8 , 0.3 , '帝旺' , fontsize = 8 , color = 'red' ) if tianpan = = '癸' : plt.text( 0.8 , 0.3 , '病' , fontsize = 8 , color = 'green' ) if x = = '坎' : if tianpan = = '壬' : plt.text( 0.75 , 0.3 , '帝旺' , fontsize = 8 , color = 'red' ) if tianpan = = '丙' or tianpan = = '戊' : plt.text( 0.75 , 0.3 , '胎' , fontsize = 8 ) if tianpan = = '辛' : plt.text( 0.75 , 0.3 , '长生' , fontsize = 8 , color = 'red' ) if x = = '離' : if tianpan = = '己' or tianpan = = '丁' : plt.text( 0.75 , 0.3 , '临官' , fontsize = 8 , color = 'red' ) if tianpan = = '庚' : plt.text( 0.75 , 0.3 , '沐浴' , fontsize = 8 ) if tianpan = = '丙' or tianpan = = '戊' : plt.text( 0.75 , 0.3 , '帝旺' , fontsize = 8 , color = 'red' ) if x = = '震' : if tianpan = = '丁' or tianpan = = '己' : plt.text( 0.75 , 0.3 , '病' , fontsize = 8 , color = 'green' ) if tianpan = = '壬' : plt.text( 0.75 , 0.3 , '死' , fontsize = 8 , color = 'green' ) if tianpan = = '丙' or tianpan = = '戊' : plt.text( 0.75 , 0.3 , '沐浴' , fontsize = 8 ) if x = = '艮' : if tianpan = = '癸' : plt.text( 0.75 , 0.3 , '沐浴冠带' , fontsize = 5 ) if tianpan = = '乙' : plt.text( 0.75 , 0.3 , '帝旺' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.3 , '衰' , fontsize = 5 , color = 'green' ) if x = = '乾' : if tianpan = = '丙' or tianpan = = '戊' : plt.text( 0.75 , 0.3 , '墓绝' , fontsize = 8 , color = 'green' ) if tianpan = = '丁' or tianpan = = '己' : plt.text( 0.75 , 0.3 , '胎养' , fontsize = 8 ) if x = = '巽' : if tianpan = = '乙' : plt.text( 0.75 , 0.3 , '冠带沐浴' , fontsize = 5 ) if tianpan = = '庚' : plt.text( 0.75 , 0.3 , '长生' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.3 , '养' , fontsize = 5 ) if x = = '坤' : if tianpan = = '丁' or tianpan = = '己' : plt.text( 0.75 , 0.3 , '冠带沐浴' , fontsize = 5 ) if tianpan = = '壬' : plt.text( 0.75 , 0.3 , '长生' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.3 , '养' , fontsize = 5 ) if tianpan = = '丙' or tianpan = = '戊' : plt.text( 0.75 , 0.3 , '衰病' , fontsize = 8 , color = 'green' ) if tianpan = = '辛' : plt.text( 0.75 , 0.3 , '衰' , fontsize = 5 , color = 'green' ) plt.text( 0.85 , 0.3 , '帝旺' , fontsize = 5 , color = 'red' ) try : plt.text( 0.01 , 0.3 , jihe[ '天盤' ][ 1 ][x]) if x = = '兌' : if jihe[ '天盤' ][ 1 ][x] = = '辛' : plt.text( 0.11 , 0.3 , '临官' , fontsize = 8 , color = 'red' ) if x = = '坎' : if jihe[ '天盤' ][ 1 ][x] = = '辛' : plt.text( 0.11 , 0.3 , '长生' , fontsize = 8 , color = 'red' ) if jihe[ '天盤' ][ 1 ][x] = = '丁' or jihe[ '天盤' ][ 1 ][x] = = '己' : plt.text( 0.11 , 0.3 , '绝' , fontsize = 8 , color = 'green' ) except KeyError as err: pass else : pass #地盘干 dipan = jihe[ '地盤' ][x] plt.text( 0.65 , 0.1 , dipan) #地盘十二长生 if x = = '兌' : if dipan = = '癸' : plt.text( 0.8 , 0.1 , '病' , fontsize = 8 , color = 'green' ) if dipan = = '乙' : plt.text( 0.8 , 0.1 , '绝' , fontsize = 8 , color = 'green' ) if x = = '坎' : if dipan = = '乙' : plt.text( 0.75 , 0.1 , '病' , fontsize = 8 , color = 'green' ) if dipan = = '庚' : plt.text( 0.75 , 0.1 , '死' , fontsize = 8 , color = 'green' ) if x = = '離' : if dipan = = '丙' or dipan = = '戊' : plt.text( 0.75 , 0.1 , '帝旺' , fontsize = 8 , color = 'red' ) if dipan = = '己' or dipan = = '丁' : plt.text( 0.75 , 0.1 , '临官' , fontsize = 8 , color = 'red' ) if x = = '震' : if dipan = = '己' or dipan = = '丁' : plt.text( 0.75 , 0.1 , '病' , fontsize = 8 , color = 'green' ) if dipan = = '丁' or dipan = = '己' : plt.text( 0.75 , 0.1 , '病' , fontsize = 8 , color = 'green' ) if dipan = = '壬' : plt.text( 0.75 , 0.1 , '死' , fontsize = 8 , color = 'green' ) if dipan = = '丙' or dipan = = '戊' : plt.text( 0.75 , 0.3 , '沐浴' , fontsize = 8 ) if x = = '艮' : if dipan = = '丁' : plt.text( 0.75 , 0.1 , '死墓' , fontsize = 8 , color = 'green' ) if dipan = = '丙' or dipan = = '戊' : plt.text( 0.75 , 0.1 , '长生' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.1 , '养' , fontsize = 5 ) if x = = '乾' : if dipan = = '壬' : plt.text( 0.75 , 0.1 , '冠带' , fontsize = 5 ) plt.text( 0.85 , 0.1 , '临官' , fontsize = 5 , color = 'red' ) if dipan = = '丙' or dipan = = '戊' : plt.text( 0.75 , 0.1 , '墓绝' , fontsize = 8 , color = 'green' ) if x = = '巽' : if dipan = = '庚' : plt.text( 0.75 , 0.1 , '长生' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.1 , '养' , fontsize = 5 ) if dipan = = '癸' : plt.text( 0.75 , 0.1 , '胎养' , fontsize = 8 ) if x = = '坤' : if dipan = = '丙' or dipan = = '戊' : plt.text( 0.75 , 0.1 , '衰病' , fontsize = 8 , color = 'green' ) if dipan = = '辛' : plt.text( 0.75 , 0.1 , '衰' , fontsize = 5 , color = 'green' ) plt.text( 0.85 , 0.1 , '帝旺' , fontsize = 5 , color = 'red' ) if dipan = = '丁' or dipan = = '己' : plt.text( 0.75 , 0.1 , '冠带沐浴' , fontsize = 5 ) if dipan = = '壬' : plt.text( 0.75 , 0.1 , '长生' , fontsize = 5 , color = 'red' ) plt.text( 0.85 , 0.1 , '养' , fontsize = 5 ) #八门 men = jihe[ '門' ][x] plt.text( 0.4 , 0.1 , men) zhishi = jihe[ '值符值使' ][ '值使門宮' ] if men = = zhishi[ 0 ]: plt.text( 0.25 , 0.1 , '值使' , fontsize = 8 , color = 'red' ) #九星 xing = jihe[ '星' ][x] plt.text( 0.4 , 0.3 , xing) if xing = = '禽' : plt.text( 0.5 , 0.3 , '芮' ) if xing = = jihe[ '天乙' ]: plt.text( 0.25 , 0.3 , '天乙' , fontsize = 8 , color = 'red' ) #八神 shen = jihe[ '神' ][x] if shen = = '勾' : plt.text( 0.4 , 0.5 , '虎' ) elif shen = = '雀' : plt.text( 0.4 , 0.5 , '武' ) else : plt.text( 0.4 , 0.5 , shen) maxing = jihe[ '馬星' ] kongwang = jihe[ '日空' ] #巽四宫 gong4 = plt.subplot(gs[ 0 , 0 ]) plt.title( "巽四宫叁肆伍捌" ) paipan( '巽' ) if dipan = = '壬' or tianpan = = '壬' : plt.text( 0.1 , 0.6 , '壬六击' ) if dipan = = '癸' or tianpan = = '癸' : plt.text( 0.05 , 0.3 , '癸六击' ) if dipan = = '庚' or tianpan = = '庚' : plt.text( 0.65 , 0.7 , '巳申刑' , color = 'red' ) plt.text( 0.75 , 0.6 , '无因之刑' , fontsize = 5 ) #门迫 if men = = '驚' or men = = '開' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #马星 if maxing = = '巳' or maxing = = '辰' : plt.text( 0.85 , 0.85 , '马' ) #震三宫 gong3 = plt.subplot(gs[ 1 , 0 ]) plt.xlabel( "震三宫叁肆捌" , fontsize = 8 ) paipan( '震' ) if dipan = = '戊' or tianpan = = '戊' : plt.text( 0.05 , 0.3 , '戊六击' ) #门迫 if men = = '驚' or men = = '開' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #空亡 if '卯' in kongwang: plt.text( 0.8 , 0.85 , '○' ) #艮八宫 gong8 = plt.subplot(gs[ 2 , 0 ]) plt.xlabel( "艮八宫伍柒捌拾" ) paipan( '艮' ) if dipan = = '庚' or tianpan = = '庚' : plt.text( 0.05 , 0.3 , '庚六击' ) if men = = '杜' or men = = '傷' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #空亡 if '寅' in kongwang or '丑' in kongwang: plt.text( 0.8 , 0.85 , '○' ) #离九宫 gong9 = plt.subplot(gs[ 0 , 1 ]) plt.title( "离九宫贰叁柒玖" ) paipan( '離' ) if dipan = = '辛' or tianpan = = '辛' : plt.text( 0.05 , 0.3 , '辛六击' ) if men = = '休' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #空亡 if '午' in kongwang: plt.text( 0.8 , 0.85 , '○' ) #中五宫 gong5 = plt.subplot(gs[ 1 , 1 ]) plt.xticks([]) plt.yticks([]) plt.xlabel(jihe[ '局数' ], fontsize = 8 ) plt.text( 0.35 , 0.8 , jihe[ '干支' ][ 0 : 3 ]) plt.text( 0.35 , 0.6 , jihe[ '干支' ][ 3 : 6 ]) plt.text( 0.35 , 0.4 , jihe[ '干支' ][ 6 : 9 ], color = 'red' ) plt.text( 0.35 , 0.2 , jihe[ '干支' ][ 9 :], color = 'red' ) plt.text( 0.02 , 0.85 , jihe[ '節氣' ], fontsize = 9 ) dipan5 = jihe[ '地盤' ][ '中' ] plt.text( 0.85 , 0.1 , dipan5) #坎一宫 gong1 = plt.subplot(gs[ 2 , 1 ]) plt.xlabel( "坎一宫壹陆" ) paipan( '坎' ) if men = = '死' or men = = '生' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #空亡 if '子' in kongwang: plt.text( 0.8 , 0.85 , '○' ) #坤二宫 gong2 = plt.subplot(gs[ 0 , 2 ]) plt.title( "坤二宫贰伍捌拾" ) paipan( '坤' ) #六仪击刑 if dipan = = '己' or tianpan = = '己' : plt.text( 0.05 , 0.3 , '己六击' ) #门迫 if men = = '杜' or men = = '傷' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #空亡 if '未' in kongwang or '申' in kongwang: plt.text( 0.8 , 0.85 , '○' ) #兑七宫 gong7 = plt.subplot(gs[ 1 , 2 ]) plt.xlabel( "兑七宫贰肆柒玖" , fontsize = 8 ) paipan( '兌' ) if men = = '景' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) #乾六宫 gong6 = plt.subplot(gs[ 2 , 2 ]) plt.xlabel( "乾六宫壹肆陆玖" ) paipan( '乾' ) if men = = '景' : plt.text( 0.5 , 0.05 , '门迫' , fontsize = 9 , color = 'green' ) if '戌' in kongwang or '亥' in kongwang: plt.text( 0.75 , 0.8 , '○' ) if maxing = = '亥' : plt.text( 0.85 , 0.8 , '马' , color = 'blue' ) plt.savefig( 'test' , dpi = 1200 ) plt.show() |
代码已经超过300行了,但是很难简略,今天的效果如下:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)