Reputation: 6796
I have a dataframe as below. Index is blank for some rows. I want to plot it and my code is as below
marker
It is appearing only for few points - how could i show all the points?lst = [5,10,8,7,8,4,6,8,9]
df = pd.DataFrame(lst, index =['a', '', '', 'd', '', '', '','e','f'], columns =['Names'])
df
#how to show poings with missing index and how to rotate x axis labels by 90 degree?
import seaborn as sns
#sns.set(rc = {'figure.figsize':(20,10)})
plt.figure(figsize = (20,10))
plot=sns.lineplot(data=df['Names'],marker='o')
#plot.set_xticklabels(plot.get_xticklabels(),rotation = 30)
Upvotes: 0
Views: 949
Reputation: 80459
You could use a dummy np.arange
for the x-axis, and then relabel the x-axis.
from matplotlib import pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
df = pd.DataFrame({'Names': [5, 10, 8, 7, 8, 4, 6, 8, 9]},
index=['a', '', '', 'd', '', '', '', 'e', 'f'])
ax = sns.lineplot(x=np.arange(len(df)), y=df['Names'].values, marker='o')
ax.set_xticks([x for x, lbl in enumerate(df.index) if lbl != ''])
ax.set_xticklabels([lbl for lbl in df.index if lbl != ''], rotation=30)
ax.grid(True, axis='x')
plt.tight_layout()
plt.show()
Upvotes: 1