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

Power BI折线图:如何在连续型X轴显示首个数据年份?

实现连续型X轴显示首个年份(1972)的方法

以下是几种常见可视化工具的操作方案:

Tableau操作步骤

  • 右键点击X轴,选择「编辑轴」
  • 在弹出窗口切换到「刻度」标签页
  • 勾选「固定开始」选项,输入1972
  • 确认设置后,X轴会从1972开始显示,确保首个年份出现在轴刻度上

Python Matplotlib实现代码

import matplotlib.pyplot as plt
import pandas as pd

# 假设df是你的数据,year为年份列,value为数值列
df = pd.read_csv("your_data.csv")
min_year = 1972  # 或通过min(df['year'])自动获取数据中的首个年份

plt.plot(df['year'], df['value'])
# 固定X轴左边界为1972
plt.xlim(left=min_year)
# 确保1972出现在刻度中
current_ticks = plt.xticks()[0].tolist()
if min_year not in current_ticks:
    current_ticks.append(min_year)
    plt.xticks(sorted(current_ticks))

plt.show()

Python Plotly实现代码

import plotly.express as px
import pandas as pd

df = pd.read_csv("your_data.csv")
fig = px.line(df, x='year', y='value')

fig.update_layout(
    xaxis=dict(
        range=[1972, None],  # 固定X轴起始为1972,结束自动适配数据最大值
        tickmode='linear'
    )
)
fig.show()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 06:34:56