Skip to main content
11 votes
Accepted

Plot timings for a range of inputs

matplotlib adding stuff to the current figure is because you are not using the OO-interface. It is slightly clunkier, but allows way more freedom In my view, you ...
Maarten Fabré's user avatar
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
  • 41k
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 ...
Samwise's user avatar
  • 4,000
7 votes
Accepted

Plotting different parameterized polynoms

You're not really using numpy at the moment. If we use the simple 'translation table' below, your code would work if you just replaced the NumPy function with the Python equivalent: ...
Peilonrayz's user avatar
  • 43.4k
7 votes

Plotting a rectangular prism

Well, unfortunately you can't get any better than this (as far as I have read). And why would you use an iterator in this case ? I'd however change a bit of the structure of your code, which allows ...
Grajdeanu Alex's user avatar
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

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
  • 10k
6 votes

Python PID simulator controller output

I want to start this review by explicitly saying that I don't have a deep knowledge when it comes to matplotlib but I'll give it a try anyway Have in mind that I ...
Grajdeanu Alex's user avatar
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
  • 1,614
5 votes
Accepted

Evaluating a series of Legendre polynomials

Compute legendre(n) once per loop iteration instead of twice. Use np.hypot instead of ...
Gareth Rees's user avatar
  • 49.6k
5 votes
Accepted

Histogram of a string

Your code is pretty good! I have only one substantive and a few stylistic suggestion. Style Since sentence is a hard-coded variable, Python convention is that it ...
Curt F.'s user avatar
  • 1,606
5 votes
Accepted

Modified Taylor diagrams

Let's start with the obvious remarks about whitespace: Whitespace is important in Python. You got trailing whitespaces all over the place and you use an indentation of 2 spaces where 4 is prescribed ...
Mast's user avatar
  • 13.4k
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
  • 41k
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,385
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
  • 62.5k
5 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
  • 1,614
4 votes
Accepted

Multigeneration evolution simulator, graphing phenotypic change

For python an official styleguide exists, PEP 8. It recommends: 4 spaces per indentation level (there are a few instances where you have 5) descriptive variable names (no single letter) in ...
Graipher's user avatar
  • 41k
4 votes

Plotting different parameterized polynoms

Here's my reworking of the calculation functions. Graphs look similar (didn't check details) when using the arange version of ...
hpaulj's user avatar
  • 1,491
4 votes
Accepted

Real time graph simulation of dice tossing

You are doing a lot of unneeded stuff. I completely deleted the for loop in the main part as well as the second plt.show. I also ...
Graipher's user avatar
  • 41k
4 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
4 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
  • 41k
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.1k
4 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
  • 41k
4 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
  • 1,614
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
  • 29.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
  • 33.8k
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
  • 1,614
3 votes
Accepted

Function Plotter GUI in Tkinter and Matplotlib

There are a lot of PEP 8 issues in your code. I recommend reading through that document. It is recommend to avoid using eval, as it makes your code harder to ...
asmeurer's user avatar
  • 276

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