Python Forum
Matplotlib scatter plot in loop with None values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib scatter plot in loop with None values
#1
Hello,

As part of a more complex project, I am trying to plot multiple curves sharing a common X axis.
However, each curve could have some None values for some X values.

When making the scatter plots through a FOR loop, I get a pretty strange result: if the first curve has None values after the fifth value, then the scatter plot of the second curve stops after the fifth value too. While the normal plot does not.

Does any of you have a suggestion?

Thanks!

import os, time, tempfile, sys
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
import matplotlib.pyplot as plt
import numpy as np
import mpld3


table = []
x = list(range(0,11))
y1 = [-90.,-91.,-87,-95,-90,-91.,None,None,None,None,None]
y2 = [-10.,-15.,-30.,-5.,-8.,-10.,-15.,-30.,-5.,-8.,0.]
table.append(x)
table.append(y1)
table.append(y2)

myDpi = 100
lineWidth = 1.
axisFontSize = 10
yAxisTitleFontSize = 10
alphaScatter = 0.5
fig, ax = plt.subplots(figsize=(1920/myDpi, 1000/myDpi), dpi=myDpi)
#plt.tight_layout()
plt.ylabel("[%]", fontsize=yAxisTitleFontSize)
ax.grid(axis='y')
ax.tick_params(axis='both', which='major', labelsize=axisFontSize)

for i in range(len(table)-1):
	line = ax.plot(table[0], table[i+1], linewidth=lineWidth)
	scatter = ax.scatter(table[0], table[i+1], alpha=alphaScatter)
	labels = ['Curve ' + str(i+1) for j in range(11)]
	mpld3.plugins.connect(fig, mpld3.plugins.PointLabelTooltip(scatter, labels=labels))

mpld3.save_html(fig,'myGraph.html') 
   
Reply
#2
The problem appears to be in mpld3. I don't have that, so I removed all references to it. Ran the script (in Colab) and got all the dots
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pick a line in a plot with matplotlib Romain 3 5,640 Feb-28-2023, 11:56 AM
Last Post: get2sid
  Matplotlib scatter plot slider with datetime sonny 0 2,962 Feb-05-2021, 02:31 AM
Last Post: sonny
  New to Python & Matplotlib - can I change the plot grid origin to lower left corner? FortyTwo 1 6,198 Aug-22-2020, 08:22 PM
Last Post: matador
  matplotlib creating a scatter plot via PathCollection tpourjalali 0 2,481 Apr-11-2020, 05:59 PM
Last Post: tpourjalali
  How to add lables to the scatter plot? Jack_Sparrow 3 3,273 Dec-11-2019, 10:20 PM
Last Post: Larz60+
  How to create correct scatter plot for PCA? LK91 0 2,111 Dec-11-2019, 07:53 PM
Last Post: LK91
  It doesn't show scatter plot but it says: "<Figure size 640x480 with 1 Axes>" dcardonaa 0 3,501 Oct-10-2019, 02:34 AM
Last Post: dcardonaa
  MatPlotLib 2d plot of current density? ruben 0 2,205 May-13-2019, 06:47 AM
Last Post: ruben
  Bar Plot with Python ,matplotlib and sqlite3 tables gauravbhardwajee 0 4,965 Sep-25-2018, 06:17 PM
Last Post: gauravbhardwajee
  Draw a square-aspect log-linear plot via matplotlib Antonio 4 8,422 Jun-19-2018, 05:57 PM
Last Post: Antonio

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020