graphpyx# How to generate an horizontal color axis in pyx density style?

In python pyx one can make color density plots such as this example:

```
from pyx import *
# Mandelbrot calculation contributed by Stephen Phillips
# Mandelbrot parameters
re_min = -2
re_max = 0.5
im_min = -1.25
im_max = 1.25
gridx = 100
gridy = 100
max_iter = 10
# Set-up
re_step = (re_max - re_min) / gridx
im_step = (im_max - im_min) / gridy
d = []
# Compute fractal
for re_index in range(gridx):
re = re_min + re_step * (re_index + 0.5)
for im_index in range(gridy):
im = im_min + im_step * (im_index + 0.5)
c = complex(re, im)
n = 0
z = complex(0, 0)
while n < max_iter and abs(z) < 2:
z = (z * z) + c
n += 1
d.append([re, im, n])
# Plot graph
g = graph.graphxy(height=8, width=8,
x=graph.axis.linear(min=re_min, max=re_max, title=r"$\Re(c)$"),
y=graph.axis.linear(min=im_min, max=im_max, title=r'$\Im(c)$'))
g.plot(graph.data.points(d, x=1, y=2, color=3, title="iterations"),
[graph.style.density(gradient=color.rgbgradient.Rainbow)])
g.writePDFfile()
```

The problem with that color legend is that if I have a page with fixed width, the whole image gets rescaled such that the width of the graph is reduced with respect to other graphs, in order to include the color bar. I would like to make the color bar horizontal above the graph to avoid this problem. Is there any easy fix to this? I could not find anything on the manual.

Solution

You can generate the keygraph yourself with settings as needed:

```
kg = graph.graphx(ypos=-3, length=8, direction="horizontal", x_title="iterations")
```

and pass it to the density style:

```
g.plot(graph.data.points(d, x=1, y=2, color=3),
[graph.style.density(gradient=color.rgbgradient.Rainbow, keygraph=kg)])
```

In order to see it, also need to add it to the graph (which is a canvas) like this:

```
g.insert(kg)
```

Result:

- Creating dijkstras algorithm and having issues in C language
- What does negative flow on a reverse arc of a graph in Boykov-Kolmogorov max flow algorithm mean?
- gnuplot: plot points with color based values in one string column and show string in legend
- Writing a DFS with iterative deepening without recursion
- For given sequences, build graph which will contain path for each sequence
- Billboardjs - Hatched bar graph
- ECharts Confidence Band (Line) chart defaulting to 0 with null values
- Imitating the waterfall plots in Origin with Matplotlib
- Shortest distance with complex number in network x
- Is there a way to customise panel titles in an effects plot?
- Find high weighted mutal friend in Neo4J Database
- How to update axes when value on dropdown changes with go.Bar() (plotly)?
- GraphFrames Pregel doesn't converge
- Which is faster and why? Set or List?
- ggplot2 Recreate horizontal rectangles like another graph
- Pyramid density plot in R
- Side by Side plot with one legend in ggplot2
- Graph issues in Gnuplot - It doesn't fully draw
- Modification of Dijkstra's algorithm to make it work with negative weights and its time complexity
- Convert list of lists into connected components of a graph to find node degrees
- Fast Convertion From Adjacency List to Edge List
- Creating Relationships in Neo4j Without Recreating Nodes
- Creating a lift chart in R
- How to make multiple graphs with fig, ax
- View Firewalls and virtual networks settings values for storage accounts using azure graph
- Partition graph into groups of neighbours having the same class
- Mailboxusage report via Graph api gives back hash values
- Plot arrow on each point towards the line in graph
- Jax Implementation of function similar to Torch's 'Scatter'
- Finding length of shortest cycle in undirected graph