Superimpose circles on a contourf plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Superimpose circles on a contourf plot

SilverSurfer
This post has NOT been accepted by the mailing list yet.
Dear all
I am new to matplotlib and python. Up until now i was able to achieve what i wanted, but now i run into a weird problem. If i superimpose markers onto a countourf plot they change their size when i zoom into and area off the plot.
The information i use to plot the positions of the circles is gathered from ASE (Atomic Simulation Environment ).

I will first try to outline my code without suppling a MWE as this would be hard to do at the moment:
__________________________
.....
from matplotlib import pyplot
from matplotlib.patches import Circle
from ase.io import read, write
from ase import Atom
from ase.atoms import Atoms
import pylab



#xarray,yarray are the x and y coordinates ,DATA contains a density at this point
niso=1#min max value
ncontours=512# number off contours
###ploting starts here

myplot = pylab.contourf(xarray,yarray,DATA,ncontours,antialiased=False,cmap=my_cmap,vmin=-niso,vmax=niso)

atoms=read('somedata', format="vasp")

for atom in atoms
        color = my_colors_DCLN[atom.number]
        radius = radii[atom.number]
        struc = pylab.plot(atom.x, atom.y, color='black', linestyle='solid', marker='o', markerfacecolor=color, markersize=(1.2+radius*3.8),alpha=0.45)
        #circle = Circle((atom.x, atom.y), (radius/3.5), facecolor=color,edgecolor='k', linewidth=0.4)#alpha=10)
        #ax.add_patch(circle))

#ax.axis('equal')
#ax.set_xticks([])
#ax.set_yticks([])
#ax.axis('off')




density_plot  
pylab.axis('image')
plt.Figure()

plt.draw()


pylab.show()
_______________________

If i use the normal markers from matplotlib everything works correct. My DATA  that i plot with contourf has the same dimensions as the atoms object. So i only need to have the xy coordinates of this object.
I can plot the atoms object fine if i do it like this:

____________
import numpy as np
from matplotlib import pyplot
from ase.lattice.surface import fcc111
from ase import Atom
from ase.data import covalent_radii as radii
from ase.data.colors import jmol_colors
from matplotlib.patches import Circle
from ase.io import read, write
fig, ax = pyplot.subplots()


atoms = read('somedata', format="vasp")





for atom in atoms:
        color = my_colors[atom.number]
        radius = radii[atom.number]
        circle = Circle((atom.x, atom.y), (radius), facecolor=color,edgecolor='k', linewidth=0.4)
        ax.add_patch(circle)

# Enforce the circles are round (equal x and y scales) and turn off
# tickmarks.
ax.axis('equal')
ax.set_xticks([])
ax.set_yticks([])
ax.axis('off')

fig.savefig('out.png',dpi=300)

pyplot.draw()


pyplot.show()
_____________________


But i do not know what "fig, ax = pyplot.subplots()" does and how i could incoporate this code in a way that i can supperimpose it to my contourf plot. The Contourf plot is the important information and i just want to show the positions of certian atoms ( circles) ontop of this plot.

Thank you in advance

fabian
Loading...