Partially transparent scatter plot, but with a solid color bar
In Python, with Matplotlib, how to simply do a scatter plot with transparency (alpha < 1), but with a color bar that represents their color value, but has alpha = 1?
Here is what one gets, with from pylab import *; scatter(range(10), arange(0, 100, 10), c=range(10), alpha=0.2); color_bar = colorbar()
:
How can the color bar be made non-transparent?
PS: I tried color_bar.set_alpha(1); draw()
, but this did not do anything…
Asked by: Chester914 | Posted: 30-11-2021
Answer 1
Alright, I found one way to do it, that looks relatively clean: (using the ColorBar
object from the question)
color_bar.set_alpha(1)
color_bar.draw_all()
# pylab.draw() or pyplot.draw() might be necessary
It would be great to get a confirmation that this is the most robust way to proceed, though! :)
Answered by: John264 | Posted: 01-01-2022Answer 2
This is a huge, ugly hack. But no other way would work. Maybe someone else can improve.
fig1 = pylab.figure()
fig2 = pylab.figure()
ax1 = fig1.add_subplot(111)
ax2 = fig2.add_subplot(111)
ax1.scatter(range(10), range(10), c=range(10), alpha=0.2)
im = ax2.scatter(range(10), range(10), c=range(10), alpha=1.0)
fig1.colorbar(im, ax=ax1)
fig1.show()
Similar questions
python - How to add a partially transparent image to Tkinter?
I am making a game in Tkinter and I would really like partially transparent images in the game for obvious reasons...
How would I do that? PNG doesn't allow transparency, and JPEG does allow transparency but isn't considered an 'image file'... What file type would allow that? Can I use bitmap somehow to make a JPEG useable? Thanks!
Some use info:
I started learning Python 3 months ago and am not hor...
python - (ursina) Prevent partially transparent model
I'm using Ursina with Python3.8 to do some 3D world stuff.
I wanted to load in a 3D model of the portal gun, just to see if I could do it. I've done that sucessfully, but it looks weird. I've attached some screenshots so you can see what I mean.
As far as I can tell, it looks like the surface i'm looking at on the model is transparent... and i'm seeing the inside of the model.
I want the portal g...
python - How to make a surface with a transparent background in pygame
Can someone give me some example code that creates a surface with a transparent background in pygame?
python - How to use PIL to make all white pixels transparent?
I'm trying to make all white pixels transparent using the Python Image Library. (I'm a C hacker trying to learn python so be gentle)
I've got the conversion working (at least the pixel values look correct) but I can't figure out how to convert the list into a buffer to re-create the image. Here's the code
img = Image.open('img.png')
imga = img.convert("RGBA")
datas = imga.getdata()
newData = list()
for i...
pygame - Updating part of a surface in python, or transparent surfaces
I have an application written in python that's basically an etch-a-sketch, you move pixels around with WASD and arrow keys and it leaves a trail. However, I want to add a counter for the amount of pixels on the screen. How do I have the counter update without updating the entire surface and pwning the pixel drawings?
Alternatively, can I make a surface that's completely transparent except for the text so you can se...
django - python PIL - background displayed opaque instead of transparent
I want to generate 32x32 sized thumbnails from uploaded images (actually avatars).
To prevent a thumbnail from being smaller than that size, I want to create a transparent 32x32 background and paste the thumbnail on it.
The code below tries to do so. However, the avatar is displayed on a black and opaque background; I lose transparency information somewhere through the process. Where am I doing wrong?...
python - Transparent FrameBuffer background in OpenGL
I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a texture which is rendered to the screen.
I want everything which is rendered to the framebuffer to kept their transparency. I just want to change the background.
See the following code:
def create_texture(surface):
surface...
How do I create a Status Icon / System Tray Icon with custom text and transparent background using Python and GTK?
Here is the code that I have so far to define the icon:
icon_bg = gtk.gdk.pixbuf_new_from_file('gmail.png')
w, h = icon_bg.get_width(), icon_bg.get_height()
cmap = gtk.gdk.Colormap(gtk.gdk.visual_get_system(), False)
drawable = gtk.gdk.Pixmap(None, w, h, 24)
drawable.set_colormap = cmap
gc = drawable.new_gc()
drawable.draw_pixbuf(gc, icon_bg, 0, 0, 0, 0, w, h)
drawn_icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPAC...
python - How to make cStringIO transparent to another function that expects a real local file
I came up with the following problem: CODE A works right now.. I am saving a png file called chart.png locally, and then I am loading it into the proprietary function (which I do not have access).
However, in CODE B, am trying to use cStringIO.StringIO() so that I do not have to write the file "chart.png" to the disk. But I cannot find a way to pass it to the pproprietaryfunction because it is expecting a real fil...
python - PIL: How to make area transparent in PNG?
I've been using PIL to crop Images, now I also want to make certain rectangular areas transparent, say
from PIL import Image
im = Image.open("sample.png")
transparent_area = (50,80,100,200)
...
python - Matplotlib transparent line plots
I am plotting two similar trajectories in matplotlib and I'd like to plot each of the lines with partial transparency so that the red (plotted second) doesn't obscure the blue.
EDIT: Here's the image with transparent lines.
python - Transparent 3D bar graphs
I would like to generate 3D bar graphs with transparent surfaces so that I can see what is going on behind tall bars.
The mplot3d API docs say that keywords are allowed for the bar3d function. I pass all the required parameters but can only output graphs with solid surfaces.
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python