1

I'm trying to plot some data that I have and I'm having issues with the x-axis tick labels. Does anyone have a fix for this? Also, is there an easier way to plot this data with certain conditions? For example, I'm looking at poker hands here, and I only want to plot this data for individuals that have over 50 hands (ie. data points). To do this, I created a new list and filtered out those with Hands < 50, is there a way of plotting this with pandas without creating a new list?

## For data handling
import pandas as pd
import numpy as np

from pandas import plotting

## For plotting
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.figure import Figure

preflop = pd.read_csv("all_player_preflop_report_tourney.csv", thousands=',')
#preflop['Hands'] = preflop['Hands'].astype(int) if preflop['Hands'] < 20000

preflop['Hands'] = preflop['Hands'].astype(int)
preflop = preflop.rename(columns={'BB/100':'BB_100','Raise First':'RFI','WTSD %': 'WTSD', 'All-In Adj BB/100':'adj_BB_100','Avg PF All-In Equity':'pf_all_in','CC 2Bet PF':'cc_2bet','3Bet PF':'3bet','2Bet PF & Call 3Bet':'2Bet_call_3Bet','Raise & 4Bet+ PF':'rfi_and_4bet+','2Bet PF & Fold':'2bet_and_fold','5Bet+ PF':'5bet+','3Bet PF & Fold':'3bet_and_fold','Call Any PFR':'call_any_pfr','Call Steal':'call_steal', 'Call vs BTN Open':'call_btn_open','CC 3Bet+ PF':'cc_3bet+','Limp Behind':'limp_behind','Raise Limpers':'raise_limpers'})
preflop = preflop.set_index('Player')


preflop_copy = preflop.copy()

preflop_train = preflop_copy.sample(frac = .75, random_state = 250)

preflop_test = preflop_copy.drop(preflop_train.index)

## first make a figure
## this makes a figure that is 8 units by 8 units
plt.figure(figsize = (8,8))


preflop_50 = preflop_copy.loc[(preflop_copy.Hands > 100)]
        
#preflop_50.plot.scatter(x="RFI", y="BB_100")
plt.scatter(preflop_50.RFI,preflop_50.BB_100)
x = np.arange(0,1,0.1)
plt.xticks(x)
#Figure.align_xlabels(plot)

## Always good practice to label well when
## presenting a figure to others
## place an xlabel
plt.xlabel("RFI", fontsize =16)

## place a ylabel
plt.ylabel("BB/100", fontsize = 16)

## type this to show the plot
plt.show()

enter image description here

Alex
  • 6,610
  • 3
  • 20
  • 38
jonstoeber
  • 19
  • 1
  • 1
    When you set `plt.xticks(x)` you are changing the x axis. What do you see when you remove this line? – Alex May 09 '21 at 13:52
  • When I remove that code the entire x axis is a blur, it looks like the numbers are overlapping themselves, making the numbers unreadable – jonstoeber May 09 '21 at 18:25
  • It's not really clear what you are asking. What is the xaxis issue, crowding? When you say with certain conditions do you mean filtering your data? This would be easier to help you debug with a [mcve]; you should also look at [good pandas questions](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and edit your question to include some example data. – Alex May 09 '21 at 18:41

0 Answers0