title: How to manually set x-ticks in sns with python
body: <p>How is x-ticks manually set in seaborn sns in python?</p>
  <p>This might be a duplicate of: <a href="https://stackoverflow.com/questions/56605113/how-to-set-x-axis-ticklabels-in-a-seaborn-plot">How to set x axis ticklabels in a seaborn plot</a>, but the solution did not work for us.</p>
  <hr />
  <p><a href="https://i.stack.imgur.com/BNeqU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BNeqU.png" alt="enter image description here" /></a></p>
  <p>We would like the x-ticks to start from 2020-01, but as data is only available from 2020-02, it doesn't automatically start the x-ticks on 2020-01. Although it will be an empty space, we would still like to include 2020-01. Following is the function.</p>
  <pre><code>def create_lineplot(dataframe):
  
      months = mdates.MonthLocator()  # every month
      years_fmt = mdates.DateFormatter('%Y-%m')  # This is a format. Will be clear in Screenshot
  
      # Filtering data to only select relevant columns and data from the year 2020
      dataframe = dataframe[['dev_id', 'temp_20', 'temp_60', 'datetime']]
      dataframe[&quot;datetime&quot;] = pd.to_datetime(dataframe[&quot;datetime&quot;])
      soil = dataframe[dataframe['datetime'].dt.year == 2020]
  
      fig, axes = plt.subplots(figsize=(20, 2))
  
      mdf = pd.melt(soil, id_vars=['datetime', 'dev_id'], var_name=['Temperature'])
  
      g = sns.relplot(data=mdf, x='datetime', y='value', kind='line', hue='Temperature', height=5, aspect=3)
      g._legend.remove()
  
      axes.xaxis.set_major_locator(months)
      axes.xaxis.set_major_formatter(years_fmt)
      axes.xaxis.set_minor_locator(months)
  
      plt.xticks(rotation='vertical')
      plt.tight_layout()
      plt.legend(loc='upper right')
  
      plt.savefig('lineplot.png')
  
      plt.show()
  </code></pre>
  <p>When we include following:</p>
  <pre><code>g.set_xticklabels(['2020-01','2020-02','2020-03','2020-04','2020-05','2020-06','2020-07','2020-08', '2020-09', '2020-10', '2020-11', '2020-12'])
  </code></pre>
  <p>between</p>
  <pre><code>g = sns.relplot(data=mdf, x='datetime', y='value', kind='line', hue='Temperature', height=5, aspect=3)
  --- HERE ---
  g._legend.remove()
  </code></pre>
  <p>then the tick is added as desired, but the values are stretched so it seems like there is data in 2020-01 as well.</p>
  <p><a href="https://i.stack.imgur.com/ruAI2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ruAI2.png" alt="enter image description here" /></a></p>
  <p>Following is an example of the data:</p>
  <p><a href="https://i.stack.imgur.com/QcDve.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QcDve.png" alt="enter image description here" /></a></p>
  <p><strong>Bonus</strong></p>
  <p>How to align the ticks after adding a new?</p>
  <p><a href="https://i.stack.imgur.com/MWPex.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MWPex.png" alt="enter image description here" /></a></p>