z-axis scaling and limits in a 3-D scatter plot

2024/7/27 20:53:44

I performed a Monte Carlo inversion of three parameters, and now I'm trying to plot them in a 3-D figure using Matplotlib. One of those parameters (Mo) has a variability of values between 10^15 and 10^20 approximately, and I'm interested in plotting the good solutions (blue dots), which vary from 10^17 to 10^19. I'm plotting the parameter (Mo) in the z-axis, and would be great to set only this axis to be logarithmic with the range of values that matters. I tried different options that I saw in other forums, but the plot does not work properly ... Maybe there is a bug in Matplotlib, or I'm not using the commands correctly.

This is the original figure with linear axes and without restricting the z-axis: enter image description here

If I try to set the z-axis as logarithmic (by adding the line ax.set_zscale('log')), the resulting scaling does not seem to work properly, because the ordering of each power is not equally spaced: enter image description here

And finally, If I try to limit the z-axis to the range of values that I'm interested (by simply adding the line ax.set_zlim3d(1e17,1e19)), instead of cutting the dots to the defined range in this axis, they seem to scape from the graph: enter image description here

This is the entire code for this figure in particular. It is not complicated. Any help or advice would be very welcome.

fig = figure(2)
ax = fig.add_subplot(111, projection='3d')# Plot models:
p = ax.scatter(Vr,Dm,Mo,c=misfits,vmin=0.3,vmax=1,s=2,edgecolor='none',marker='o')
fig.colorbar(p, ticks=arange(0.3,1+0.1,0.1))# Plot settings:
ax.set_xlim3d(0,max(Vr))
ax.set_ylim3d(0,max(Dm))
ax.set_zlim3d(1e17,1e19)
ax.set_zscale('log')
ax.set_xlabel("$V_{r}$ [$km/s$]")
ax.set_ylabel("$D_{max}$ [$m$]")
ax.set_zlabel("$M_{o}$ [$Nm$]")
ax.invert_xaxis()
jet()
title("Kinematic parameters and $M_{o}$")
Answer

This is possibly related to this issue. It's suggested to plot np.log10(z) instead of z with log scale. You might want to change your code to:

fig = figure(2)
ax = fig.add_subplot(111, projection='3d')# Plot models:
p = ax.scatter(Vr,Dm,np.log10(Mo),c=misfits,vmin=0.3,vmax=1,s=2,edgecolor='none',marker='o')
fig.colorbar(p, ticks=arange(0.3,1+0.1,0.1))# Plot settings:
ax.set_xlim3d(0,max(Vr))
ax.set_ylim3d(0,max(Dm))
ax.set_zlim3d(17,19)
ax.set_xlabel("$V_{r}$ [$km/s$]")
ax.set_ylabel("$D_{max}$ [$m$]")
ax.set_zlabel("$M_{o}$ [$Nm$]")
ax.invert_xaxis()
jet()
title("Kinematic parameters and $M_{o}$")

I also suggest to use tight_layout(). At least on my machine, axis labels are not shown properly without it. Here's the picture with some fake data:

enter image description here

https://en.xdnf.cn/q/72652.html

Related Q&A

How to fix value produced by Random?

I got an issue which is, in my code,anyone can help will be great. this is the example code.from random import * from numpy import * r=array([uniform(-R,R),uniform(-R,R),uniform(-R,R)])def Ft(r):f…

Can I safely assign to `coef_` and other estimated parameters in scikit-learn?

scikit-learn suggests the use of pickle for model persistence. However, they note the limitations of pickle when it comes to different version of scikit-learn or python. (See also this stackoverflow qu…

How to update the filename of a Djangos FileField instance?

Here a simple django model:class SomeModel(models.Model):title = models.CharField(max_length=100)video = models.FileField(upload_to=video)I would like to save any instance so that the videos file name …

CSS Templating system for Django / Python?

Im wondering if there is anything like Djangos HTML templating system, for for CSS.. my searches on this arent turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I …

How to use chomedriver with a proxy for selenium webdriver?

Our network environment using a proxy server to connect to the outside internet, configured in IE => Internet Options => Connections => LAN Settings, like "10.212.20.11:8080".Now, Im…

django application static files not working in production

static files are not working in production even for the admin page.I have not added any static files.I am having issues with my admin page style.I have followed the below tutorial to create the django …

Celery task in Flask for uploading and resizing images and storing it to Amazon S3

Im trying to create a celery task for uploading and resizing an image before storing it to Amazon S3. But it doesnt work as expected. Without the task everything is working fine. This is the code so fa…

Python logger formatting is not formatting the string

Following are the contents of mylogger.py:def get_logger(name=my_super_logger):log = logging.getLogger(name)log.setLevel(logging.DEBUG)formatter = logging.Formatter(fmt=%(asctime)s %(name)s %(message)s…

Python subprocess.Popen.wait() returns 0 even though an error occured

I am running a command line utility via Pythons subprocess module. I create a subprocess.Popen() object with the command line arguments and stdout=subprocess.PIPE and then I use subprocess.wait() to w…

Better way to call a chain of functions in python?

I have a chain of operations which needs to occur one after the other and each depends on the previous functions output.Like this:out1 = function1(initial_input) out2 = function2(out1) out3 = function3…