3

I am trying to draw a scatter plot with Plotly Express and facing a problem when setting the size of the markers. So this is the NumPy array that contains the numerical values in accordance to which, I want the marker size.

[0.         0.         0.         0.         0.         0.
 0.         0.         0.53061224 0.65306122 0.28571429 1.
 0.48979592 0.53061224 0.         0.65306122]

When I set the arguments in

px.scatter(size = size_array)

The markers on the plot with size 0 gets dissapeared, because literaly they have 0 size.

Is there any workaround this? So that markers which get 0 value are also visible on the plot?

I've attached the plot screenshot for reference, thanks.

screenshot

EDIT I have replicated the whole issue here: https://gist.github.com/SakshamSingh-v2/5eb27d728f572c97ad67a4e5def346c0

Also One solution is to add a constant to the whole array, basically increasing the 0 to some value, but here the values represent severity. So increasing these values might give a mis-representation. I am thinking of a solution like in which I could map the 0 to some specified marker size.

Saksham Singh
  • 51
  • 1
  • 6
  • Please share your complete code with imports. And preferrably a data sample of your data like [this](https://stackoverflow.com/questions/63163251/pandas-how-to-easily-share-a-sample-dataframe-using-df-to-dict/63163254#63163254) – vestland Apr 09 '21 at 10:48

2 Answers2

2

Yes, you can set the sizemin attribute (in pixels!): https://plotly.com/python/reference/scatter/#scatter-marker-sizemin

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
  • Thanks for the reference! Tried but I guess I didn't figure out how it works. So here is what I did, **fig = px.scatter(x = data['a'], y = data['b'], color = data['type'].astype(str), size = data['severity'], template = 'plotly_dark') fig.update_traces(marker_sizemin = 0.1) fig.show()** But the 0's are still invisible. I've replicated the whole issue here, please go through this link: https://gist.github.com/SakshamSingh-v2/5eb27d728f572c97ad67a4e5def346c0 – Saksham Singh Apr 09 '21 at 14:51
  • @SakshamSingh There shouldn't be any reason to go to an off-site resource to look into the details of your issues here. Please consider showing clearly ***in your question*** what you've tried, and also include a sample of your data. I've already provided a link on how to do that below your question. – vestland Apr 09 '21 at 19:05
  • 1
    `sizemin` is specified in *pixels*, so it's normal that 0.1 doesn't give you much. Try 5 or 10. – nicolaskruchten Apr 10 '21 at 20:44
-1

Maybe you can copy that array and add constant value. So difference between initial values remain the same.

0 -> 1.00000000 0.53061224 -> 1.53061224

For hover information you can select your original array.

Akroma
  • 1,150
  • 7
  • 13
  • 1
    Actually, the values represent Severity, so if I add some constant and use that to represent, It might give a wrong insight as Severity 0 means completely well, and higher values show the increase. So I was thinking of an approach in which I can map a default marker size on 0. Thanks for the suggestion! – Saksham Singh Apr 09 '21 at 14:20