Skip to content
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

Add tick labels to ternary suface plot #1

Open
zhongjingjogy opened this issue Sep 24, 2016 · 2 comments
Open

Add tick labels to ternary suface plot #1

zhongjingjogy opened this issue Sep 24, 2016 · 2 comments

Comments

@zhongjingjogy
Copy link

Hello,

I'm writing a piece of code to visualize a ternary surface. The surface and the framework seems ok for me, but no labels for the ticks are available. It seems that lineticks package is suitable for this and I have try to use adapt to the current case with Axes3D. Unfortunately, the linesticks do not work as expectation and I would like to seek some help for you.

Figure 1 is the figure that I would to add some ticks and label.
figure_1

I would like to provide the source code for your convenience.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
from lineticks import LineTicks

def frame(ax, zlims):
    x = np.linspace(0, 1.0, 20)
    y = x*0.0
    ax.plot(x*0.0, y*0.0, color="blue", zs=np.linspace(zlims[0], zlims[1], 20))
    ax.plot(0.5*(y + 1.0), (y+1.0)*0.5*np.sqrt(3.0), color="blue", zs=np.linspace(zlims[0], zlims[1], 20))
    ax.plot(x*0.0 + 1.0, y*0.0, color="blue", zs=np.linspace(zlims[0], zlims[1], 20))
    # line - 1
    x = np.linspace(0, 0.5, 20)
    y = np.sqrt(3)*x
    line1, = ax.plot(x, y, color="blue")
    ax.plot(x, y, zs=np.max(z), color="blue")
    major_ticks = LineTicks(line1, range(20), 20,lw=1,color='r', direction=-1)

    # line - 2
    x = np.linspace(0.5, 1.0, 20)
    y = -np.sqrt(3)*x + np.sqrt(3)
    ax.plot(x, y, color="blue")
    ax.plot(x, y, zs=np.max(z), color="blue")

    # line - 1
    x = np.linspace(0, 1.0, 20)
    y = x*0.0
    ax.plot(x, y, color="blue")
    ax.plot(x, y, zs=np.max(z), color="blue")
    return ax

x = []
y = []
for x1 in np.arange(0, 1, 0.05).tolist():
    for x2 in np.arange(0, 1.0 - x1, 0.05).tolist():
        x.append(x1 + 0.5*x2)
        y.append(x2*0.5*np.sqrt(3.0))

z = np.array(x)**2 + np.array(y)**2

# Triangulate parameter space to determine the triangles
tri = mtri.Triangulation(x, y)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

# The triangles in parameter space determine which x, y, z points are
# connected by an edge
ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral)
ax.set_axis_off()

n = 10
dr = 2.0/n
sqrt3 = np.sqrt(3.0)

ax = frame(ax, [np.min(z), np.max(z)])

plt.show()

Best wishes!

Jing

@xnx
Copy link
Owner

xnx commented Sep 24, 2016

Hi Jing,
The problem I see with this is that lineticks was only designed to work on 2-D plots and it doesn't know how to draw ticks on a 3-D canvas. In your case, for example, when you add ticks to one of the frame lines, which direction should they point in?
If I think of a solution that works for both 2-D and 3-D, I'll let you know!

@zhongjingjogy
Copy link
Author

Hi,

That's very kind of you! I think we might setup some rules for directions. The ticks should be perpendicular to the line. When the norm directions are alternative, one can preset them certain directions. In my case, two kinds of ticks are needed. The first one is on the xoy plane and the second is along the z-axis.

Another project might related to this issue, so I paste it here for your convenience.
marcharper/python-ternary#54

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

No branches or pull requests

2 participants