Skip to content

[Bug]: Inward direction of ticks works on 2d, but not 3d projections #21729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ghost opened this issue Nov 23, 2021 · 3 comments
Open

[Bug]: Inward direction of ticks works on 2d, but not 3d projections #21729

ghost opened this issue Nov 23, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 23, 2021

Bug summary

for 2D:

plt.tick_params(axis='x', which='major', direction='in')
plt.tick_params(axis='y', which='major', direction='in')

this works. While on 3D projections:

ax.tick_params(axis='x', which='major', direction='in')
ax.tick_params(axis='y', which='major', direction='in')
ax.tick_params(axis='z', which='major', direction='in')

it is ignored.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
import math

N = 100000
y = np.random.rand(N)

s1 = 0.5
y1 = y + np.random.normal(0.0, s1,(N))

s2 = 0.8
y2 = y + np.random.normal(0.0, s2,(N))

alphaOpti1 = s2*s2 / (s1*s1+s2*s2)
alphaOpti2 = s1*s1 / (s1*s1+s2*s2)
sOpti = math.sqrt(s1*s1*s2*s2/(s1*s1+s2*s2))
print('Computed', alphaOpti1, alphaOpti2, sOpti)

a1 = []
a2 = []
s = []
sO = []
for alpha in range(101):
    alphaX = alpha / 100.0
    yy = alphaX * y1 + (1.0 - alphaX) * y2
    a1.append(alphaX)
    a2.append(1.0-alphaX)
    s.append(math.sqrt(np.sum((yy-y)**2)/(N-1.0)))
    sO.append(sOpti)

pos = np.argmin(s)
print('Simulated', a1[pos], a2[pos], s[pos])

plt.figure(figsize=(10,10))    
plt.plot(a1,s,'r')
plt.plot(a1,sO,'g')
plt.plot([alphaOpti1],[sOpti],'bo')
plt.xlabel(r"$\alpha$")
plt.ylabel(r"$\sigma_B^2$")
plt.tick_params(axis='x', which='major', direction='in')
plt.tick_params(axis='y', which='major', direction='in')
plt.grid()
plt.show()

import numpy as np
import matplotlib.pyplot as plt
import math

N = 100000
y = np.random.rand(N)

s1 = 0.65
y1 = y + np.random.normal(0.0, s1,(N))

s2 = 0.8
y2 = y + np.random.normal(0.0, s2,(N))

s3 = 1.1
y3 = y + np.random.normal(0.0, s3,(N))

alphaOpti1 = s2*s2*s3*s3 / (s1*s1*s2*s2+s1*s1*s3*s3+s3*s3*s2*s2)
alphaOpti2 = s1*s1*s3*s3 / (s1*s1*s2*s2+s1*s1*s3*s3+s3*s3*s2*s2)
alphaOpti3 = s1*s1*s2*s2 / (s1*s1*s2*s2+s1*s1*s3*s3+s3*s3*s2*s2)

sOpti = math.sqrt(s1*s1*s2*s2*s3*s3/(s1*s1*s2*s2+s1*s1*s3*s3+s3*s3*s2*s2))
print('Computed:', alphaOpti1, alphaOpti2, alphaOpti3, sOpti)

a1 = []
a2 = []
a3 = []
s = []
sO = []
for alpha1 in range(101):
    alpha1X = alpha1 / 100.0
    for alpha2 in range(101):
        alpha2X = alpha2 / 100.0
    
        alpha3X = 1.0 - alpha1X - alpha2X
        if alpha3X >= 0:
            yy = alpha1X * y1 + alpha2X * y2 + alpha3X * y3

            a1.append(alpha1X)
            a2.append(alpha2X)            
            a3.append(alpha3X)   
            s.append(math.sqrt(np.sum((yy-y)**2)/(N-1.0)))
            sO.append(sOpti)
    
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')

pos = np.argmin(s)
print('Simulated:', a1[pos], a2[pos], a3[pos], s[pos])

ax.scatter(a1,a2,s,c='r',alpha=0.1)
ax.scatter(a1,a2,sO,c='g',alpha=0.1)
ax.scatter([alphaOpti1],[alphaOpti2],[sOpti],c='b')
ax.set_xlabel(r"$\alpha_1$")
ax.set_ylabel(r"$\alpha_2$")
ax.set_zlabel(r"$\sigma_B^2$")
ax.tick_params(axis='x', which='major', direction='in')
ax.tick_params(axis='y', which='major', direction='in')
ax.tick_params(axis='z', which='major', direction='in')
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
plt.show()

Actual outcome

for 2d ticks are only in, while for 3d ticks are going out as well (command ax.tick_params(axis='z', which='major', direction='in') is ignored for x, y, z)

Expected outcome

ticks only going in.

Additional information

No response

Operating system

Feren OS

Matplotlib Version

3.5.0

Matplotlib Backend

QtAgg

Python version

Python 3.8.10

Jupyter version

No response

Installation

pip

@ghost
Copy link
Author

ghost commented Nov 23, 2021

2d
3d

@timhoffm
Copy link
Member

If somebody is interested in working on this, the relevant code starts here:

@ghost ghost mentioned this issue Feb 21, 2022
@oscargus
Copy link
Member

oscargus commented Apr 14, 2022

Looking through old issues and found this #790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants