Python Forum
[Solved] Matplotlib - Tricontour: how to set colorbar range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Matplotlib - Tricontour: how to set colorbar range
#1
I would like to set the colorbar range, when plotting my data, using tricontour.

What I have tried:
vmin=0.13, vmax=0.4
to enforce min and max, but it did not show any difference.

plt.clim(0.13,0.4)
which creates an error:
RuntimeError: You must first define an image, e.g., with imshow
Here is my code, you can find "data.csv" as attachement to this message.

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.tri as tri

# load data
df = pd.read_csv("data.csv", sep=";")

# specify x, y, z
x = df.iloc[:, 0]
y = df.iloc[:, 1]
z = df.iloc[:, 2]

# create plot
fig, ax = plt.subplots(nrows=1)

# contoure
ax.tricontour(x, y, z, levels=14, linewidths=0.5, colors='k',vmin=0.13, vmax=0.4) 
# filling
cntr2 = ax.tricontourf(x, y, z, levels=14, cmap="RdBu_r",vmin=0.13, vmax=0.4) 
# colorbar
fig.colorbar(cntr2, ax=ax)
# dots
ax.plot(x, y, 'ko', ms=3) 

# Equal aspect ratio 
plt.gca().set_aspect('equal', adjustable='box')
# plt.clim(0.13,0.4) 
plt.show()

Attached Files

Thumbnail(s)
   

.csv   data.csv (Size: 373 bytes / Downloads: 196)
Reply
#2
I found the solution by myself: via levels you can specify the exact vector for the colorbar range.

levels =[0.1,0.2,0.3,0.4]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,367 May-14-2023, 04:29 PM
Last Post: Winfried
  matplotlib x axis range goes over the set range Pedroski55 5 3,111 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,162 Mar-11-2021, 10:52 AM
Last Post: buran
  Plotting 3D Data with Custom Colorbar Gates666 0 1,668 Jul-09-2020, 10:56 AM
Last Post: Gates666
  colorbar for scatter shows no negatives values... gil 0 1,514 Apr-15-2020, 12:45 AM
Last Post: gil
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 6,878 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  Matplotlib Colorbar Ticks (Increase number) BennyS 1 8,779 Apr-18-2018, 04:00 PM
Last Post: BennyS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020