Skip to main content
10 votes

Modifying Titration Data analysis results

I've never used numpy or matplotlib, so I can only speak to issues of style. You're allowing for far too much nesting here. Your code consists of a giant, dense, deeply nested chunk. As a result, the ...
Carcigenicate's user avatar
9 votes
Accepted

Farthest point algorithm in Python

First, a style comment. On the internet, especially in programming, and in particular on this website, English is the lingua franca. So you should avoid mixing other languages and English. This way ...
Graipher's user avatar
  • 41.7k
9 votes
Accepted

Python Sound visualizer

Nice. Here are some observations: consider using an IntEnum: This helps remove "magic" numbers from the source code. (A year from now, will you remember that <...
RootTwo's user avatar
  • 10.7k
8 votes
Accepted

A Python script to plot data and save to PDF

coding style Your code is almost pep-8 compliant. There are a few spaces missing after comma's, but all in all this is not too bad. I myself use black to take care of this formatting for me. some of ...
Maarten Fabré's user avatar
8 votes

Modifying Titration Data analysis results

I'm going to put this code into an editor, "proofread" it from top to bottom, give notes as I go, and then paste the final result to show the effect of the edits. Code editors don't usually wrap lines ...
Samwise's user avatar
  • 4,010
7 votes
Accepted

Calculating relay operating times, according to IEC 60255

You need not declare # -*- coding: utf-8 -*- in Python 3: UTF-8 is the default. Writing I = np.logspace(…) inside your ...
200_success's user avatar
7 votes
Accepted

Implementing a joint differential equation and eigenvalue solver

My primary goal here is to verify the correctness of my method and its implementation in code You've done some things well - you have seemingly descriptive variable names and comments. You need to ...
Reinderien's user avatar
  • 71.2k
6 votes

Compute and plot a 2D vector field with radial symmetry in Python

Is there a suitable plotting function allowing to avoid to compute and store the two potentially large arrays u and v, and ...
tdy's user avatar
  • 2,266
6 votes
Accepted

Plotting Collatz conjecture values - Python

Note how you're manually repeating the number of seeds (1500): colors = plt.cm.bwr(np.linspace(0, 1, 1500)) for i in range(1, 1500): ... That's always a good ...
tdy's user avatar
  • 2,266
5 votes
Accepted

Probability of event using Central Limit Theorem + plotting results

You seem to know about str.format (since you use it), yet you are still doing string addition: ...
Graipher's user avatar
  • 41.7k
5 votes
Accepted

Pythonic way of managing data for plotting 2D variance plots

Your function proc can be greatly reduced by using the fact that numpy functions are vectorized and most of them take the axis ...
Graipher's user avatar
  • 41.7k
5 votes
Accepted

Image processing and plotting

Usually, when using for loops and numpy together, you’re probably doing it wrong. Some things you could replace in your code: Use ...
301_Moved_Permanently's user avatar
5 votes
Accepted

Measure size of repository as a function of time

This is good, useful, powerful. Let's make it better! There's no need for os here, so remove it. os.curdir can just be ...
Reinderien's user avatar
  • 71.2k
5 votes
Accepted

Modularizing matplolib graphing based on a data dictionary

The biggest challenge I had with understanding how your code works was around what panelize's and single_plot's ...
Peilonrayz's user avatar
  • 44.6k
5 votes
Accepted

Python implementation of approximating the chance a particle is at a location after n steps in the cardinal directions

Your directions dictionary is only used by get_direction; why not put it inside the function rather than have it as a global? I'...
QuantumChris's user avatar
  • 1,405
5 votes
Accepted

Predator-prey simulation

Shebang #!/opt/anaconda3/bin/python This is suspicious. Usually you should just #!/usr/bin/env python and make sure that ...
Reinderien's user avatar
  • 71.2k
5 votes

Python Sound visualizer

In addition to what RootTwo already mentioned, I would also advise to: Define all class attributes in __init__ When I want to understand a new class, the first ...
Ivo Merchiers's user avatar
5 votes

Plotting shapely polygon in matplotlib

Unfortunately I don't know of a better way (but have also not looked into one, tbh). Here are some comments on your pathify method instead. You are currently ...
Graipher's user avatar
  • 41.7k
5 votes
Accepted

groupby in pandas and plot

J_H's advice about DRY is good for Python in general. However for Pandas in particular, we should almost never iterate. Instead we chain methods that operate on the calling object. Here your repeated ...
tdy's user avatar
  • 2,266
4 votes

MCMC Metropolis Hastings for German Tank Puzzle

A lot needs to change for this to be an efficient Monte Carlo simulation. All use of the uniform stats object should be removed. It's really slow, and that's ...
Reinderien's user avatar
  • 71.2k
4 votes
Accepted

Live plot with many subplots

First notice that you're using essentially none of the features of matplotlib. There are no titles, axis labels or annotations of any kind. Your example assumes that ...
Reinderien's user avatar
  • 71.2k
4 votes

Sum, validate, and plot monthly inventory levels

DataFrame.append has been deprecated and is no longer available, so your code does not run. If you use a pathlib.Path and make ...
Reinderien's user avatar
  • 71.2k
4 votes
Accepted

Calculating pi via collisions

I am currently using the RK-4 method to update position Firstly, the naming is unhelpful here. A name like RK4_1 implies that the method does the quadrature. I ...
Peter Taylor's user avatar
  • 24.5k
4 votes
Accepted

Matplotlib real-time monitor with reversed time

UX The GUI looks great, and the message at the top of the graph is helpful. However, exiting out of the GUI is a little awkward. When I click on the "x", the GUI window closes, but I still ...
toolic's user avatar
  • 16.4k
4 votes

Demonstrate the central limit theorem

Some suggestions: Black will reformat this code to a recognizable and very readable layout. Concatenating strings using + is not pythonic. The standard way to do ...
l0b0's user avatar
  • 9,117
4 votes
Accepted

Optimizing Multiple Subplot Visualization and Navigation in Matplotlib

cached bitmaps Consider asking matplotlib to save a .PNG copy of each displayed plot. Then you can rapidly switch between them upon encountering a cache hit. Consider employing the streamlit library, ...
J_H's user avatar
  • 43.3k
4 votes

Plotting Collatz conjecture values - Python

Integer arithmetic seed = seed/2 takes the value of seed (initially an integer) and divides it by 2, and stores the result as a <...
AJNeufeld's user avatar
  • 35.3k
4 votes
Accepted

Collatz conjecture plots (python)

Since there is only 1 argument ... what I cannot understand is why it doesn't put collatz_values on the x axis. That's just how matplotlib implemented it. If you ...
tdy's user avatar
  • 2,266
4 votes
Accepted

Slack User Interaction Graph – Collaboration Topology

There are many examples in the code where mutable structures should be made immutable. To your credit, most of the code workflow is already reasonable insofar as lack of mutation; you just need to ...
Reinderien's user avatar
  • 71.2k
3 votes
Accepted

Regularised regression code

You can get rid of some of the repetition using a for loop looping over the lambdas and colors and using tuple assignment to at least get rid of one level of having ...
Graipher's user avatar
  • 41.7k

Only top scored, non community-wiki answers of a minimum length are eligible