-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matplotlib basemap colorbar exception : Given element not contained in the stack #544
Comments
Hi @redstoneleo! Sorry for the late reply. I have taken your example snippet and I paste it here for the record: import sys
import numpy as np
from matplotlib import cm
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from mpl_toolkits.basemap import Basemap
from PyQt5 import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
button1 = QtWidgets.QPushButton("button1")
button2 = QtWidgets.QPushButton("button2")
self.map_canvas = FigureCanvas(Figure(figsize=(20, 20)))
self.map_toolbar = NavigationToolbar(self.map_canvas, self)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
lay = QtWidgets.QGridLayout(central_widget)
lay.addWidget(button1, 0, 0)
lay.addWidget(button2, 0, 1)
lay.addWidget(self.map_canvas, 1, 0, 1, 2)
self.addToolBar(self.map_toolbar)
button1.clicked.connect(self.update_plot)
button2.clicked.connect(self.update_plot)
self.ax = self.map_canvas.figure.subplots()
self.ax.set_axis_off()
def update_plot(self):
self.ax.clear()
m = Basemap(width=12000000, height=9000000, projection="lcc",
resolution="c", lat_0=19., lon_0=73., ax=self.ax)
m.drawcoastlines(linewidth=1)
x, y, z = np.random.rand(3, 1000000)
x *= 12e6
y *= 9e6
z *= 20000
gridsize = 100
m.hexbin(x, y, C=z, gridsize=gridsize, cmap=cm.YlGnBu)
# cb = m.colorbar()
self.map_canvas.draw()
if __name__ == "__main__":
app = QtWidgets.QApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_()) If If I uncomment
So I can confirm you that something is not working with |
please see it at matplotlib/matplotlib#23186
The text was updated successfully, but these errors were encountered: