Create own colormap using matplotlib and plot color scale

There is an illustrative example of how to create custom colormaps here. The docstring is essential for understanding the meaning of cdict. Once you get that under your belt, you might use a cdict like this: Although the cdict format gives you a lot of flexibility, I find for simple gradients its format is rather unintuitive. Here is a utility function … Read more

Changing the “tick frequency” on x or y axis in matplotlib?

You could explicitly set where you want to tick marks with plt.xticks: For example, (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) The plt.plot (or ax.plot) function will automatically set default x and y limits. If you wish to keep those limits, and just change the stepsize of the tick marks, then you could use ax.get_xlim() to discover what limits Matplotlib … Read more

Error in plot.window(…) : need finite ‘xlim’ values

The problem is that you’re (probably) trying to plot a vector that consists exclusively of missing (NA) values. Here’s an example: In your example this means that in your line plot(costs,pseudor2,type=”l”), costs is completely NA. You have to figure out why this is, but that’s the explanation of your error. From comments: Scott C Wilson: Another possible cause of … Read more