Reputation: 11
When plotting via plot(x, y), the x values have 2 uses:
I am looking for a way how to get rid of the second use, i.e. I want the non-equidistant x positions displayed in a equidistant way.
Example: When the data points (0,0), (1,1), (4,4), (9,9) are given, plotting plot(x, y) gives a straight line. But I rather want them to be displayed as parabola, just like if I plotted (0,0), (1,1), (2,4), (3,9), but with correct ticking and grid lines for the original x data 0, 1, 4, 9. I.e. the x axes should be warped for display, and the x values should only be used for grid and tick positions with correct tick lables. The tick/grid positions should still be numeric, i.e. it should be possible to set them independent from the the x data values, or use the clever automatic behaviour to determine best positions.
It is obvious that determining the grid/tick positions is not directly possible since the warping function is not given explicitly, but it could be interpolated from the x values. It is also okay to set the warping function explicitely.
Actually, the warping function is not completely arbitrary, but rather monotonous. But it is not a simple built-in warping like log.
It is somehow related to warping the x axis for display only, by using the 'xscale' option. The difference is that I would to have the warping in the x data themselves as well as in the display to habe a better resolution.
Is there a way to do that?
Upvotes: 1
Views: 571
Reputation: 80459
You could make the x-values categorical by converting them to strings. Here is an example:
import matplotlib.pyplot as plt
import numpy as np
points = [(0, 0), (1, 1), (4, 4), (9, 9)]
x = [str(xi) for xi, yi in points]
y = [yi for xi, yi in points]
fig, ax = plt.subplots()
ax.plot(x, y)
ax.grid(True)
plt.show()
Upvotes: 0