These are chat archives for sandialabs/toyplot

24th
Jan 2017
Deren Eaton
@dereneaton
Jan 24 2017 00:58
Hi @tshead, I'm having trouble aligning text under a graph. When I add scatterplot points they seem to align correctly, but text does not. Here is an example:
## make a canvas
canvas = toyplot.Canvas(width=500, height=350)

## the graph data
xcoords = [0, 2, 5, 4]
ycoords = [0, 3, 2, 1]
coords = np.array([xcoords, ycoords]).T
edges = np.array([[0, 1], [0, 2], [1, 2], [2, 3]])

## plot graph on top half
axes = canvas.cartesian(bounds=(50, 450, 50, 250))
axes.graph(edges, vcoordinates=verts, ewidth=3, vsize=20)
axes.x.ticks.labels.show = False

## add scatter below graph
axes = canvas.cartesian(bounds=(50, 450, 275, 300))
axes.scatterplot(xcoords, [100 for i in coords], size=15)
axes.show = False

## add text below
axes = canvas.cartesian(bounds=(50, 450, 300, 350))
axes.text(xcoords, [100 for i in coords],
          text=range(4), 
          color=toyplot.color.Palette()[1],
          style={'font-size': '20px', 
                 "text-anchor":"start",}
          )
axes.show = False
image.png
The difference being that text seems to be squeezed towards the center.
Timothy M. Shead
@tshead2
Jan 24 2017 07:05
What's happening is that your third set of axes aren't lining-up with the first two, because part of the range is being set aside for the text. You can see a clearer example of this at http://toyplot.readthedocs.io/en/stable/labels-and-legends.html#coordinate-system-text
Timothy M. Shead
@tshead2
Jan 24 2017 07:12
As a general rule, the right way to keep things lined up is to use a single set of coordinate axes. Since you're assigning explicit y coordinates anyway, it won't add any additional work. To posit ion the X axis between the graph and the scatter plot, you can set it explicitly with axes.x.spine.position - see http://toyplot.readthedocs.io/en/stable/cartesian-coordinates.html#properties for details.
For the y axis, you can use toyplot.locator.Explicit to label (or not) each of the "layers" in the plot. See