Edges of Bases of Plots do not reach appropriate points
andrewkhardy opened this issue · 2 comments
Thanks for making this package. Hopefully this is a simple fix.
I'm trying to make some 3D line plots with the fill_between to distinguish boundaries. However, based on how I orient the plot, the lines appear to truncate at different spots or go off the grid. How do I manage to get the base of the lines to effectively end at the actual coordinates that have been assigned to them? I've checked the arrays I'm using at they do have the correct base values, it's just a plotting distortion.
Without going into the data I'm using, the actual plotting script is
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(111,projection='3d')
ax.plot(*peak1, lw=2, zorder=20, c="red")
fill_between_3d(ax, *base1, *peak1, mode = 1, c="red")
ax.plot(*peak2, lw=2, zorder=20, c="orange")
fill_between_3d(ax, *base2, *peak2, mode = 1, c="orange")
ax.plot(*peak3, lw=2, zorder=20, c="blue")
fill_between_3d(ax, *base3, *peak3, mode = 1, c="blue")
ax.view_init(30, 20)
ax.set_ylabel("t")
ax.set_xlabel(r"$\delta t$")
ax.set_zlabel("T")
#ax.invert_xaxis()
ax.set_ylim(0.07, 0.19)
plt.show()
Hello, Andrew. Thank you for asking! I hope I understood your question correctly.
I believe that Matplotlib is considering automatic vertical axis limits for your plot. That is, it is considering the minimum and maximum values of the set of plotted lines as the limits, excluding the polygons that draw the areas under the lines. This would cause the base of the colored areas to be shown off the vertical limits of the grid.
As far as I'm concerned, the usual solution to this, when working with polygon collections, is to set the axis limits explicitely as you have already done with the y axis. I guess that your base z axis (T axis) values could be equal to 0 at all points, so maybe the workaround is to use ax.set_zlim(zmin=0)
, although you may change the 0 by the actual minimum value of your bases.
I do not have the data corresponding to your peak and base arrays, so I have tried to replicate it approximately. Your question has been very useful because I have found that, by replacing line 64 of the FillBetween3d.py
file by [(x2[len(x2)-i-1],y2[len(x2)-i-1],z2[len(x2)-i-1]) for i in range(len(x2))]
, you may obtain smoother areas under your lines as shown in the image below using the option mode = 2
.
I say this because I realized that if you used the current definition of the mode = 2
with the data, the drawn areas would be a mess.
If it is no problem, could you please tell me if, by replacing line 64 ,
mode = 2
works well for you with your data? If it works I will add the correction to the main code in the repository.
On the other hand, I find this for some view angles:
Here, the orange line is shown in front of the blue area, although it is actually behind it. I'm sorry, but I do not know a solution for this. As far as I know, this is due to a clipping problem that Matplotlib has in 3D plots involving polygon collections and lines, but I could be wrong and it is solved in newer versions of Matplotlib.
As a final note, I have found that the Matplotlib documentation offers an example for filling areas under graphs in 3D plots:
https://matplotlib.org/stable/gallery/mplot3d/polys3d.html
If the fill_between_3d
function in this repository doesn't fully satisfy you, maybe you find this useful.
I hope my answer is helpful! If you have more questions, please tell me.