1
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

d = {'x-axis':[100,915,298,299], 'y-axis': [1515,1450,1313,1315],
     'text':['point1','point2','point3','point4']}
df = pd.DataFrame(d)

p1 = sns.relplot(x='x-axis', y='y-axis',data=df )
ax = p1.axes[0,0]
for idx,row in df.iterrows():
    x = row[0]
    y = row[1]
    text = row[2]
    ax.text(x+.05,y,text, horizontalalignment='left')

plt.show()

Here How I can decide x-axis range. I mean I want that x-axis should be 0 50 100 150 etc and I want yaxis to be 0 500 1000 1500 etc and also I make sure that both axes are starting from 0

azro
  • 53,056
  • 7
  • 34
  • 70
Bhupinder Kaur
  • 89
  • 3
  • 11
  • "Range" refers to the minimum and maximum values for the axis. It sounds like what you want to set is the "tick". I'm new to seaborn and don't know how to do this, but hopefully this clarification in terminology can help you better google for what you need. – Code-Apprentice Nov 19 '19 at 21:32
  • Maybe https://stackoverflow.com/questions/44521648/tick-frequency-when-using-seaborn-matplotlib-boxplot will help. – Code-Apprentice Nov 19 '19 at 21:34

1 Answers1

3

You can do the following - using the line

p1.set(xticks=[i for i in range(0, max(df['x-axis']) + 50, 50)],
       yticks=[i for i in range(0, max(df['y-axis']) + 500, 500)])

to dynamically set the ticks.

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns

d = {'x-axis':[100,915,298,299], 'y-axis': [1515,1450,1313,1315],
     'text':['point1','point2','point3','point4']}
df = pd.DataFrame(d)

p1 = sns.relplot(x='x-axis', y='y-axis',data=df )
ax = p1.axes[0,0]
for idx,row in df.iterrows():
    x = row[0]
    y = row[1]
    text = row[2]
    ax.text(x+.05,y,text, horizontalalignment='left')

p1.set(xticks=[i for i in range(0, max(df['x-axis']) + 50, 50)],
       yticks=[i for i in range(0, max(df['y-axis']) + 500, 500)])


plt.show()

To increase the height and width of the plot so no points overlap, just alter this line from

p1 = sns.relplot(x='x-axis', y='y-axis', data=df)

to

p1 = sns.relplot(x='x-axis', y='y-axis', data=df, height=10, aspect=1)

You can change height and aspect as you see fit.

CDJB
  • 14,043
  • 5
  • 29
  • 55
  • thanks for the answer. It is working as asked but my concern in actual to adjust the distance difference so that two points that are overlapping over each other each should be visible. – Bhupinder Kaur Nov 20 '19 at 16:13