如何将刻度标签添加到 pandas 图中?
How do I add tick labels to a pandas plot?
我有一个 pandas 数据框,我已将其绘制在绘图中,但出于某种原因,我无法让我的绘图具有 xtick 标签。我试过使用 matplotlib,但它似乎不起作用。这是我的情节。
wsdf = pd.DataFrame(list(wshots.items()),columns = ['Coordinates', 'Occurences (S, G)'])
wsdf[['S','G']] = pd.DataFrame(wsdf['Occurences (S, G)'].tolist(), index=wsdf.index)
wsdf[['X-','Y']] = pd.DataFrame(wsdf['Coordinates'].tolist(), index=wsdf.index)
wsdf['wShot Percentage'] = wsdf['G'] / wsdf['S']
wsdf = wsdf.drop(['Coordinates', 'Occurences (S, G)'], axis = 1)
wsdf['X'] = abs(wsdf['X-'])
wsdf = wsdf.drop(['X-'], axis = 1)
wsdf = wsdf[["X", "Y", "S", "G", "wShot Percentage"]]
#makes it so there aren't any coordinates that dont have more than x shots
print(wsdf)
wsdf = wsdf.loc[wsdf['S'] >=1]
# scatter plot
wshot_plot = wsdf.plot.scatter(
x='X',
y='Y',
c='wShot Percentage',
colormap='RdYlGn',
alpha = 1/3)
这就是我尝试获取 xticks 的方法
xtick = [50, 60, 70, 80, 90, 100]
plt.plot(x, y)
plt.xlabel('xtick')
plt.show()
任何事情都会有帮助!谢谢!
我想你想使用 xticks 或 xticklabels。
import matplotlib.pyplot as plt
x_vals = [55,65,75]
y_vals = [30,40,50]
fig, ax = plt.subplots()
ax.scatter(x=x_vals,
y=y_vals)
xtick = [50, 60, 70, 80, 90, 100]
ax.set_xticks(xtick) #specify where you want your ticks
# If you want the labels to be something other than the default x_tick values.
# ax.set_xticklabels(["A", "B", "C", "D", "E"])
plt.show()
我有一个 pandas 数据框,我已将其绘制在绘图中,但出于某种原因,我无法让我的绘图具有 xtick 标签。我试过使用 matplotlib,但它似乎不起作用。这是我的情节。
wsdf = pd.DataFrame(list(wshots.items()),columns = ['Coordinates', 'Occurences (S, G)'])
wsdf[['S','G']] = pd.DataFrame(wsdf['Occurences (S, G)'].tolist(), index=wsdf.index)
wsdf[['X-','Y']] = pd.DataFrame(wsdf['Coordinates'].tolist(), index=wsdf.index)
wsdf['wShot Percentage'] = wsdf['G'] / wsdf['S']
wsdf = wsdf.drop(['Coordinates', 'Occurences (S, G)'], axis = 1)
wsdf['X'] = abs(wsdf['X-'])
wsdf = wsdf.drop(['X-'], axis = 1)
wsdf = wsdf[["X", "Y", "S", "G", "wShot Percentage"]]
#makes it so there aren't any coordinates that dont have more than x shots
print(wsdf)
wsdf = wsdf.loc[wsdf['S'] >=1]
# scatter plot
wshot_plot = wsdf.plot.scatter(
x='X',
y='Y',
c='wShot Percentage',
colormap='RdYlGn',
alpha = 1/3)
这就是我尝试获取 xticks 的方法
xtick = [50, 60, 70, 80, 90, 100]
plt.plot(x, y)
plt.xlabel('xtick')
plt.show()
任何事情都会有帮助!谢谢!
我想你想使用 xticks 或 xticklabels。
import matplotlib.pyplot as plt
x_vals = [55,65,75]
y_vals = [30,40,50]
fig, ax = plt.subplots()
ax.scatter(x=x_vals,
y=y_vals)
xtick = [50, 60, 70, 80, 90, 100]
ax.set_xticks(xtick) #specify where you want your ticks
# If you want the labels to be something other than the default x_tick values.
# ax.set_xticklabels(["A", "B", "C", "D", "E"])
plt.show()