Matplotlib

This week, I decided to explore applications of programming that relate more to the world of research and data analysis... This has been QUITE a frustrating week! The benefit if turtle programs, is that there seems to be nothing that hasn't already been done already available in an internet search (I am not saying that it is easy by any means, but the process of debugging can be a bit more systematic). The Turtle project is a fantastic way to start thinking like a programmer. Once I started tackling other Python libraries, things got much less intuitive. However, I am determined to learn more libraries and continue to practice. My project for this week was to create an interactive piece of data that I felt I may be able to implement into a classroom. One of the subject areas of Physics that I struggled with the most was understanding light and the electromagnetic spectrum. The usual visuals are confusing and difficult to comprehend. Here is what is generally provided to students without mcuh explanation...
I wanted to develop something that was simpler to understand. Usually, students are presented this chart with only a baseline understanding of frequency and wavelength. I just wanted to show a simple graph showing the inverse relationship between frequency and wavelength, and only hone into visible light. Shwowing a graphic of visible light, I feel, is the best way to ease students into this topic more effectively. The graph would show increasing wavelength with a decreasing frequency, along with the associated color change as we progress through the graph. Here is the link to an interactive graph in python. Sure, I was able to find the code and run it but I wanted to make something a little different. Here, you will see a graph that I generated off of just a few lines of code. This utilizes the Matplotlib library which is a tool that can be used to provide clear graphical representations with interactive capabilities (such as save, zoom, and even a position finder in the lower right).
You will see in the code that I have been trying to figure out how to fill the area under the curve with changing colors. I have tried some for loops along with the use of the function ".fill_between". Here was a somewhat successful atttempt. I was able to fill the area under the curve (Also known as the integral.. perhaps I should use this in order to change the color as it progresses). My attempt was to only fill in a certain part of the graph for when wavelength is between 625 and 740nm. This is associated with the color red (Is also associated with frequency range of 405 to 480 Hz). I also added in some labels for the x and y axis (notice that I flipped wavelength and frequency as I felt it made more sence to have frequency on the x axis since it is more associated to time which is what students are used to seeing on the x-axis.).
I tried changing my for loop and creating a new array through numpy, thinking that maybe the list needs to be an array (main difference here is that an array has a fixed set up of values in a certain order while a list is a little more informal of a set of data... I think). However, this did not work. So here is where I stand for now with my code.
Here is a video of how you can interacti with matplotlib.
My goals for the future of this project are to do the following: Have different colors under the curve accurately representing the visible light spectrum, Turn the transitioning of colors into a gradient to show the gradual change between frequencies/wavelengths, Perhaps include a slider feature where the screen will change colors based on the freuency/wavelength selected on the slider. Any tips or pointers are invited!!!

Comments

Popular Posts