You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Matplotlib优化政治坐标图,使其贴近标准政治罗盘样式

优化Matplotlib图表为标准政治罗盘样式

下面是修改后的代码,能让你的图表更贴近标准政治罗盘的样式,包含象限标签、维度标注、背景区分等关键元素:

from matplotlib import pyplot as plt
import matplotlib.patches as patches

# 假设你的数据已定义
xs = x_values
ys = y_values

# 创建画布和轴对象
fig, ax = plt.subplots(figsize=(8, 8))

# 绘制散点数据,调整样式增强可读性
ax.scatter(xs, ys, s=40, c='darkblue', alpha=0.7, edgecolor='white')

# 设置坐标轴范围,保持原有的-11到11
ax.set_xlim(-11, 11)
ax.set_ylim(-11, 11)

# 添加中心十字线(水平线和垂直线)
ax.axhline(y=0, color='black', linewidth=1.5)
ax.axvline(x=0, color='black', linewidth=1.5)

# 给四个象限添加背景色(可选,增强区分度)
# 左上:威权左翼
ax.add_patch(patches.Rectangle((-11, 0), 22, 11, color='#e6f7ff', alpha=0.3))
# 右上:威权右翼
ax.add_patch(patches.Rectangle((0, 0), 11, 11, color='#fff2e6', alpha=0.3))
# 左下:自由左翼
ax.add_patch(patches.Rectangle((-11, -11), 22, 11, color='#f0f9e8', alpha=0.3))
# 右下:自由右翼
ax.add_patch(patches.Rectangle((0, -11), 11, 11, color='#fff0f5', alpha=0.3))

# 添加象限标签,放在每个象限中心
ax.text(-5, 5, '威权左翼', fontsize=14, ha='center', va='center', fontweight='bold')
ax.text(5, 5, '威权右翼', fontsize=14, ha='center', va='center', fontweight='bold')
ax.text(-5, -5, '自由左翼', fontsize=14, ha='center', va='center', fontweight='bold')
ax.text(5, -5, '自由右翼', fontsize=14, ha='center', va='center', fontweight='bold')

# 添加维度标注
ax.set_xlabel('经济维度(左:集体主义 → 右:个人主义)', fontsize=12, labelpad=15)
ax.set_ylabel('社会维度(下:自由 → 上:威权)', fontsize=12, labelpad=15)

# 优化坐标轴样式:只保留底部和左侧轴线,隐藏顶部和右侧
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_position('zero')
ax.spines['bottom'].set_position('zero')

# 添加刻度,调整位置
ax.set_xticks([-10, -5, 5, 10])
ax.set_yticks([-10, -5, 5, 10])
ax.tick_params(axis='both', labelsize=10)

plt.tight_layout()
plt.show()

关键优化点说明:

  • 象限区分:通过背景色和加粗标签明确四个政治象限的定位,匹配标准政治罗盘的定义
  • 维度标注:清晰标注横轴(经济)和纵轴(社会)的含义,避免歧义
  • 样式优化:调整散点大小、透明度和边框,让数据点更突出;精简坐标轴元素,保留核心参考线
  • 布局调整:使用tight_layout()确保标签和元素不重叠,图表整体更规整

你可以根据需求调整背景色、标签字体、散点样式等参数,进一步贴近目标样式。

内容的提问来源于stack exchange,提问作者Eloragh Espie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 12:57:51