3D scatter with two axes in logscale - python

I am trying to get a scatter plot with 2 axes (x,z) in a log scale using set_scale but that doesn't work.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x=np.linspace(0,500,10)
y=np.linspace(0,1,10)
z=np.linspace(0,100000,10)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot(x, y, z,'o', c='g')
ax.grid()
#ax.set_xscale('log')
#ax.set_zscale('log')
#ax.set_xlim([min(x), max(x)])
#ax.set_zlim([min(z), max(z)])
plt.show()

Related

Format the y-axis label in the higher thousands with many zeros to scientific notation?

How can I tighten the y-axis by using scientific notation?
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=[1,2,3,4,5,6,7,8,9,10]
y=np.array([1,1,1,2,10,2,1,1,1,1])*100000
ax.plot(x, y)
With plt.ticklabel_format:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=[1,2,3,4,5,6,7,8,9,10]
y=np.array([1,1,1,2,10,2,1,1,1,1])*100000
ax.plot(x, y)
plt.ticklabel_format(axis="y", style="sci", scilimits=(0,5))
plt.show()

3D plotting in Python - Adding a Legend to Scatterplot

from mpl_toolkits.mplot3d import Axes3D
ax.scatter(X_lda[:,0], X_lda[:,1], X_lda[:,2], alpha=0.4, c=y_train, cmap='rainbow', s=20)
plt.legend()
plt.show()
Essentially I'd like to add a legend for the scatterplot that shows the unique values in y_train and what color point it corresponds to on the plot.
The output plot:
Producing either a legend or a colorbar for a scatter is usually quite simple:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x,y,z = (np.random.normal(size=(300,4))+np.array([0,2,4,6])).reshape(3,400)
c = np.tile([1,2,3,4], 100)
fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
sc = ax.scatter(x,y,z, alpha=0.4, c=c, cmap='rainbow', s=20)
plt.legend(*sc.legend_elements())
plt.colorbar(sc)
plt.show()

how can I increase the space between tick labels and axes labels in matplotlib for a 3D plot?

how can I increase the space between tick labels and axes labels in matplotlib for a 3D plot?
my plot is defined in this way
import pylab
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(np.log10(NP), np.log10(NB*10**12), np.log10(NL), c='r', marker='o', lw=0)
ax.scatter(np.log10(NPd), np.log10(NBd), np.log10(NLd), c='b', marker='o', lw=0)
ax.set_xlabel('Periods', fontsize=35)
ax.set_ylabel('Magnetic', fontsize=35)
ax.set_zlabel('Luminosity', fontsize=35)
atockx = ax.xaxis.get_major_ticks()
for tockx in atockx:
tockx.label.set_fontsize(30)
atocky = ax.yaxis.get_major_ticks()
for tocky in atocky:
tocky.label.set_fontsize(30)
atockz = ax.zaxis.get_major_ticks()
for tockz in atockz:
tockz.label.set_fontsize(30)

matplotlib pcolor with modified axis

Goal: I want to modify the axis of the pcolor plot in such a way that the pcolor plot is not changed and not shifted, only the axis!
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import numpy as np
fig, ax = plt.subplots(1,1)
phi = np.random.random([20,10])
xticks = range(10)
yticks = range(10)
ax.pcolor(phi,norm=LogNorm(vmin=10E-3, vmax=10E3))
ax.set_xticks(xticks)
ax.set_xscale("log")
ax.set_yticks(yticks)
fig.show()
failed plot

Polar plot without grid in matplotlib

Is there a way to turn of the grid for polar plots in matplotlib? I tried matplotlib.pyplot.rgrids([], []), but it doesn't work.
From your axes instance, call grid(False).
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.grid(False)
r = np.arange(0,1,0.001)
theta = 2*2*np.pi*r
ax.plot(theta,r)
plt.show()

Categories

Resources