I want to remove the y axis of my matplotlib plot (maybe via pandas DataFrame.plot() method) so that it is invisible and change the x-axis to be a dotted line. The closest I've seen to this is the pyplot.box(False) statement, however it doesn't let me select just the y-axis and I still can't how to edit the x-axis as described. How do I go about doing this?
            Asked
            
        
        
            Active
            
        
            Viewed 1,486 times
        
    1
            
            
        - 
                    1Is [this](https://stackoverflow.com/a/2176591/2454357) of any help? – Thomas Kühn May 02 '19 at 08:37
1 Answers
1
            Here is one way to do it. I am choosing a sample DataFrame to plot. The trick is to hide the left, right and top axis' spine and turn the lower x-axis into dashed line using the method suggested here by @ImportanceOfBeingEarnest
import pandas as pd
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
df = pd.DataFrame({'pig': [20, 18, 489, 675, 1776],
                   'horse': [4, 25, 281, 600, 1900]
                  }, index=[1990, 1997, 2003, 2009, 2014])
ax_ = df.plot.line(ax=ax)
for spine in ['right', 'top', 'left']:
    ax_.spines[spine].set_visible(False)
ax_.spines['bottom'].set_linestyle((0,(8,5)))
plt.yticks([])
plt.show()
 
    
    
        Sheldore
        
- 37,862
- 7
- 57
- 71
- 
                    Yep this has sorted my problem completely, the spines is very useful indeed! – Alesi Rowland May 02 '19 at 10:19
 
     
    