0

So I'm plotting a solution to PDE with a program called fenics that has its own plot function. I can get the colorbar with plt.colorbar, how can I call it with fixed bounds such that the lower bound and upper bounds will always be the same regardless of data. What do I pass colorbar function so that there is a fixed lower and upper bound to the colorbar?

I have seen boundaries and ticks, but this isn't doing the trick

Eigenvalue
  • 1,093
  • 1
  • 14
  • 35
  • Possible duplicate of [Set Colorbar Range in matplotlib](https://stackoverflow.com/questions/3373256/set-colorbar-range-in-matplotlib) – jwalton Feb 18 '19 at 21:01
  • @ImportanceOfBeingErnest fenics uses a plot function, when i set the result of plotting to a variable and add a colorbar to that object it appears on the plot when I plt.show – Eigenvalue Feb 18 '19 at 23:39
  • So `out = mysterious_function(); plt.colorbar(out); plt.show()` gives you the correct colorbar? Any chance you can give a hint on `mysterious_function` to possibly identify a canonical solution? If not, `out.set_clim(vmin,vmax)` might still work. – ImportanceOfBeingErnest Feb 18 '19 at 23:47
  • When I look at the type of the variable that is returned from the fenics plot and its . It autofits the colorbar, I was interested in setting the colorbar to be for example on the interval -5 to 5 and color appropriately. – Eigenvalue Feb 19 '19 at 04:47
  • Ah, it's not possible to change the color range of a contour plot after it being created. The reason is that the contours would need to be recalculated from scratch in such case. Is there really no manual on the `mysterious_function`? – ImportanceOfBeingErnest Feb 19 '19 at 13:14
  • Not that I can find. RIP me lol :( – Eigenvalue Feb 20 '19 at 04:50

1 Answers1

0

Try something like:

normi = matplotlib.colors.Normalize(vmin=0, vmax=1.0)
plt.figure(figsize=(10,8))
plt.title('Title')
plt.xlabel('x')
plt.ylabel('y')
c = plot(u)
c.set_norm(normi)
plt.colorbar(c)
cfcm
  • 139
  • 2
  • 10