0

When I run the code below I receive a duplication within the X axis

ax = df.plot.line(x="Brand", y="Range", legend=False)
ax2 = ax.twinx()
df.plot.line(x="Brand", y="Seats", ax=ax2, legend=False, color="#d86e39")
plt.xticks(rotation='vertical')
ax.figure.legend()
plt.show()

The libraries I am using are:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from plotly.offline import iplot
import plotly as py
import plotly.tools as tls

%matplotlib inline

The image shows the repeating x-axis names

  • 1
    Hi @eglease, I really appreciate the edit as someone knew to programming. – Dashz_Altair_AFC Aug 11 '23 at 17:12
  • What libraries are you using? Please [edit] and add the tags for them. You might want to add the imports too. If it helps, it looks like Pandas, matplotlib, and Seaborn. – wjandrea Aug 11 '23 at 17:20
  • 1
    BTW, welcome to Stack Overflow! Check out the [tour], and [ask] if you want tips. I'm a bit out of my depth, but you'll probably want to make a [mre] including some example input (data), and the current outputs. – wjandrea Aug 11 '23 at 17:22
  • Hi @wjandrea, As advised I have now added in the libraries. Many thanks for your help. – Dashz_Altair_AFC Aug 11 '23 at 17:25
  • Please share what your plot currently looks like. – jared Aug 11 '23 at 18:45
  • Hi @jared, I have a screenshot of one that works and the other which isn't as expected how can I attach both? – Dashz_Altair_AFC Aug 11 '23 at 18:52
  • Hi @jared, I have attached a screenshot as requested. – Dashz_Altair_AFC Aug 11 '23 at 19:12
  • What is the duplication that you're referring to? – jared Aug 11 '23 at 19:21
  • Hi Jared, Thanks for your reply, the duplication is referring to the X-Axis naming repetition. In my CSV file, there are additional brand names but for some reason, a reduced list appears with repeated brand names as shown in the screenshot with Tesla. – Dashz_Altair_AFC Aug 11 '23 at 19:38
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Aug 11 '23 at 19:41
  • Please can my question be reopened as the duplicate claims do not answer and are differentiated from my questions. – Dashz_Altair_AFC Aug 11 '23 at 21:35
  • Some values in the 'Brand' column likely have leading or trailing spaces, which need to be removed. `df.Brand.unique()` will show all the unique values in the column. Also, it’s not an appropriate visualization for a lineplot, continuous data, to have a categorical, discrete, xaxis. The question lacks a complete [mre] and cannot be answered further. – Trenton McKinney Aug 12 '23 at 17:44
  • 1
    Hi @TrentonMcKinney, Thank you for answer. I understand something like a date field would be better suited. This is just an example chart I have created using my assignment data in the process of learning Python. I will definitely try the code you have mentioned and hopefully it resolves my issue. Have a nice and safe rest of your week. – Dashz_Altair_AFC Aug 17 '23 at 09:14

0 Answers0