Search code examples
pythonseaborn

Seaborn jointplot with defined axes limits


I am trying to generate some figures using the joint plot command of Seaborn. I have a list of tuples called "data", with the coordinates (x,y) that needed to be plotted. The x-coordinates are in range (200,1400) and the y-coordinates are in range (300,900). However, I need to show the entire region I am working, demonstrating the concentration of the points. I need the x-coordinate to be in range (0,3000) and the y-coordinate to be in range (0-1200), and I am failing to do so.

Here is my code:

import seaborn as sns
import numpy as np

np.shape(y)
xx = np.linspace(0,1080,np.shape(y))
yy = np.linspace(0,1920,np.shape(y))

sns.jointplot(xx="x", yy="y", data=data, kind="kde")

I returns the error: "TypeError: jointplot() missing 2 required positional arguments: 'x' and 'y'".

If I don't use the xx and yy variables, it gives the plot with the axes limited automatically.

enter image description here

How can I set the axes to the ranges I need?


Solution

  • You can plot your data and modify the plot's axis limits later:

    import numpy as np
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    # generate some random date
    x = np.random.normal(loc=650, scale=100, size=1000)
    y = np.random.normal(loc=600, scale=200, size=1000)
    
    plot = sns.jointplot(x, y, kind="kde")
    plot.ax_marg_x.set_xlim(0, 3000)
    plot.ax_marg_y.set_ylim(0, 1200)
    
    plt.show()