[Matplotlib-users] Changing the colorbar / Absolute marker size

Guy Léonis Guy.Leonis at spacebel.be
Tue Sep 3 02:19:51 EDT 2019

Thank you to all, and my deepest apologies to have not found related topics in archive and through googling.

I have an Earth map with markers on it. Each marker has 4 attributes: longitude, latitude, temperature and size.
In the example, positions are random.
[cid:image001.png at 01D561B5.0BD968B0]
The colorbar range is set to temperature range.
When I zoom in the map, I would like to:

-          change the displayed colorbar so that its range is set to the temperature range of the still visible markers, and change accordingly the colour of the still visible markers

-          (not yet searched for) have an absolute size for the marker (i.e. diameter is absolute on Earth)
Despite search in documentation and examples, I am unable to find a programming path.
Any suggestion would be welcomed. Current (dirty) test code of my best solution to first point is appended to this email.

Again, thank you. Best regards,


Guy Léonis
Project Manager
Ildefons Vandammestraat, 5-7 Bat B 1st floor - Hoeilaart Office Center - B-1560 HOEILAART
Tel: +32 (0) 2 658 20 11 - Fax: +32 (0) 2 658 20 90

# Import python standard libraries
import os
import sys

# Import specific libraries
import netCDF4
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

pat_version = "2"
window_id = 1
channel = 1
sample = 1
extra = "user string"
window_title = "MWS - PAT - V%s - %d - Map of channel %02d / sample %02d - %s   " \
               % (pat_version, window_id, channel, sample, extra)

lon = np.random.random(50) * 360 - 180
lat = np.random.random(50) * 180 - 90
bt = np.random.random(50) * 50 + 250
radius = np.random.random(50)

(fig, ax) = plt.subplots()
sc = None
cm = plt.get_cmap("rainbow")

def on_draw(event):
    global sc
    print("\n\nDraw event")
    (x_min, x_max) = ax.get_xlim()
    (y_min, y_max) = ax.get_ylim()
    x = []
    y = []
    z = []
    for (lx, ly, lz) in zip(lon, lat, bt):
        if (x_min < lx < x_max) and (y_min < ly < y_max):
    if sc is not None:
        print((len(z), min(z), max(z)))
        sc.set_offsets(np.c_[x, y])
        #sc = plt.scatter(x, y, s=50, c=z, marker='o', cmap=cm, vmin=int(min(z)) , vmax=int(max(z)) + 1)

draw_event_cb_id = fig.canvas.mpl_connect("draw_event", on_draw)
fig.set_size_inches(8, 4.44, forward=True)
fig.suptitle("Brightness Temperature")
plt.subplots_adjust(left=0.05, right=0.90, bottom=0.05, top=0.90)
plt.xlim(-180.0, 180.0)
plt.ylim(-90.0, 90.0)
man = plt.get_current_fig_manager()

world_path = os.getenv("MWS_HOME_PAT") + "/tools/PAT/data/world/world_010m.txt"
fp = open(world_path)
world_lines = fp.readlines()
data_x = []
data_y = []
for line in world_lines:
    if len(line) == 1:
        if len(data_x) > 0:
            plt.plot(data_x, data_y, marker="", color="black", markersize=0, linewidth=1)
            data_x = []
            data_y = []
        x, y = line.split()

#plt.imshow(lon, lat, bt, cmap=plt.get_cmap("rainbow"))
sc = plt.scatter(lon, lat, s=50, c=bt, marker='o', cmap=cm, vmin=int(min(bt)), vmax=int(max(bt)) + 1)
cax = plt.axes([0.91, 0.05, 0.02, 0.9])



The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden.

SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free.
Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail.

SPACEBEL denies all liability where E-mail is used for private use.

SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190903/4c475c93/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 108570 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190903/4c475c93/attachment-0001.png>

More information about the Matplotlib-users mailing list