7/30/2023 0 Comments Matplotlib 3d scatter axis labelNext, we call the legend() function to display the legend. Here, we want to show the difference in sizes between points that represent low, average, and high reliability. The code above is creating three additional plots so that, when the legends are created, it identifies three unique labels. savefig ( 'scatter3d.png', dpi = 300, bbox_inches = 'tight' ) plt. legend ( loc = 'upper right', bbox_to_anchor = ( 1, 0.96 ), scatterpoints = 1, ncol = 1, fontsize = 15 ) plt. max () * 200, label = 'High reliability' ) ax3d. mean () * 200, label = 'Avg reliability' ) ax3d. min () * 200, label = 'Low reliability' ) ax3d. Take a look at this page on the Lab Manual for more details on color bars, and how to make them. Once we create the plot itself, we will make the colorbar to show how the utility’s infrastructure NPC regret, NPC_regret, varies with the three values on the axes. Feel free to experiment with different scaling factors! Points of these sizes will be nearly invisible on the plot we need scale them up so they are visible on the 3D plot. This is scaling the REL values up by a factor of 200, since these values (as they are) are between the values of 0-1. The last line of code here is important: by varying the values of the azim parameter, you will be able to view the 3D plot from different angles. view_init ( elev = 30, azim = 45 ) # Set elevation and azimuth angles set_zlabel ( 'Infrastructure NPC \n (preferred) $\longrightarrow$' ) ax3d. set_ylabel ( 'Transfer trigger \n $\longleftarrow$ (increased use)', labelpad = 10 ) ax3d. set_xlabel ( 'Infrastructure trigger \n (increased use) $\longrightarrow$', labelpad = 10 ) ax3d. S = REL * 200, alpha = 0.8 ) # Set labels for the three axes ax3d. scatter ( inf_trigger, tt_trigger, INPC, c = normalize_regret ( INPC_regret ), cmap = 'viridis_r', \ Tweaking a bit harder on xaxis and zaxis doesn't do anything: ax.xaxis.labelpad = 0.# Create the scatter plot ax3d. The following brings the yaxis (realizations) quite close to the tick labels, but not xaxis and zaxis labels: ax.xaxis.labelpad = 1 So I figure reducing those numbers should bring them closer. The following pushes the labels quite far away, as expected: ax.xaxis.labelpad = 20 Without touching the padding I have (note the zaxis label for the left plot is off the fig): I just cannot get my tick labels or axis label where I want it. I feel like I have tried everything, including answers here. I should note I am using 3D subplots, perhaps that is my issue? fig = plt.figure(figsize=(3,2))Īx = fig.add_subplot(1,2,i,projection='3d') I'm using mpl 3.4.3 and I am still having this issue. Please check out the revised documentation here. Because the spacings are determined by relative proportions in mplot3d, having a smaller space to work within forces the labels closer together.Īs for other possible avenues for work-arounds, please see the note here.Ī fair warning, this private dictionary is not intended to be a permanent solution, but rather a necessary evil until the refactor of mplot3d is complete.Īlso, v1.1.0 contains many updates to the api of mplot3d. For the next release, I would like to have 3d axes to take up more than the default axes spacing, since the default was designed to take into account that tick labels and axes labels would be outside the axes, which is not the case for mplot3d. I fixed the miscalculation of axes label angles, and I made some adjustments to the spacing. V1.1.0 contains several fixes to improve the state of things. There were also bugs in how mplot3d calculated the angle to render the labels. The reason why the various tricks that typically work in regular 2d plots don't work for 3d plots is because mplot3d was originally written up with hard-coded defaults. This is useful when you have an array of axes as returned by plt.subplots, and it is more convenient than using setxticks because in that case you need to also set the tick labels, and also more convenient that those that iterate over the ticks (for obvious. I really need to follow StackOverflow more often. ax.tickparams(axis'x', labelrotation90) Matplotlib documentation reference here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |