Nov-03-2021, 01:23 PM
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!
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')
