0

我有一个 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()

任何事情都会有所帮助!谢谢!

4

1 回答 1

0

我认为您想要使用 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()
于 2020-11-28T09:15:08.283 回答