Image size of 447x412817 pixels is too large. error for sns.scatterplot

I have a dataset with 2 features with the name pos_x and pos_y and I need to scatter plot the clustered data done with DBScan. Here is what I have tried for it:

import seaborn as sns
import matplotlib.pyplot as plt
colors=['purple','red','blue','green']
    Data = []
    dataset = pd.read_csv(r'/Users/file_name.csv')
    Datadb = dataset[["pos_x","pos_y"]]
    dbscan=DBSCAN()
    clusters =dbscan.fit(Datadb.to_numpy())
    p = sns.scatterplot(data=Datadb, x="pos_x", y="pos_y", hue=clusters.labels_, legend="full", palette="deep")
    sns.move_legend(p, "upper right", bbox_to_anchor=(1.17, 1.2), title='Clusters')
    plt.show()

but it shows me the following error:

ValueError: Image size of 447x412817 pixels is too large. It must be less than 2^16 in each direction.

I even tried the following but again I got the same error!

fig = plt.gcf()
    fig.set_size_inches(12, 8)
    p = sns.scatterplot(data=Datadb, x="pos_x", y="pos_y", hue=clusters.labels_, legend="full", palette="deep")
    sns.move_legend(p, "upper right", bbox_to_anchor=(1.17, 1.2), title='Clusters')
    plt.show()

Appreciate if anyone helps me how can I set the size for sns.scatterplot because my dataset is huge, every time I run my code, it takes a lot of time to execute!

I have just a basic idea of Matplotlib, but did you check fig.dpi? See matplotlib.figure — Matplotlib 3.5.2 documentation

Also as troubleshooting steps I would try:

  • feeding just parts of the data
  • start from the most simple plot and adding features

The error message looks accurate. 216 is 65536 and 412817 is indeed beyond that range.

  1. What is the largest pos_x and pos_y value in your dataset?
  2. Is your plot origin (0,0) ?

It looks like you’re going to need to scale your scatter plot down. Will a plot with resolution 65536 x 65536 give you enough resolution? (It would seem so, but you know the demands of your application.)