[Matplotlib-users] Superimpose circles on a contourf plot

Thomas Caswell tcaswell at gmail.com
Sat Aug 5 19:37:58 EDT 2017


Fabian,

The `Circle` artist is sized in data-space so it _should_ changes sizes as
you zoom.

If you just want to show markers sized in _screen_ space use `scatter`

    sc = ax.scatter([a.x for a in atoms], [a.y for a in atoms],
s=[radii[a.number] for a in atoms])

should do the trick.

Tom

On Sat, Aug 5, 2017 at 12:36 PM SilverSurfer <ineedemail at gmx.de> wrote:

> 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
>
>
>
>
> --
> View this message in context:
> http://matplotlib.1069221.n5.nabble.com/Superimpose-circles-on-a-contourf-plot-tp48053.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170805/d116587c/attachment-0001.html>


More information about the Matplotlib-users mailing list