Code Monkey home page Code Monkey logo

pyplot-fortran's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyplot-fortran's Issues

Request for wireframe

Dear Jacob:

Is it possible to add support for wireframe style of plot? After some testing I think to add functionality of wireframe to pyplot-fortran, we only need to change this line:

CS = ax.plot_wireframe (X,Y,Z,label="muw",antialiased=False,linestyles="-",linewidths=1)

from plot_surface to plot_wireframe.

Ford API documentation

Hi Jacob,

I am using your great pyplot-fortran into WenOOF... it is half an hour and I am already addicted to it... great!

I have a request. Can you transform the docstring into ford-compliant syntax in order to produce well documented API? Or do you accept PR? In case, I can fork pyplot-fortran and submitting PR.

As you can see here pytplot-fortran API doc is missing.

Calling gca() with keyword arguments was deprecated in Matplotlib 3.4

This warning is shown while the program test.f90 is running:

orbit.py:16: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
  ax = fig.gca(projection='3d')

useOffset

add option for ax.ticklabel_format(useOffset=False)

ValueError: 'xerr' must not contain negative values

Hello!

Thanks for the great project!

I tried to build (compiles) and run tests. I got an error:

➜  pyplot-fortran git:(master) fpm build --profile release
pyplot_module.F90                      done.
libpyplot-fortran.a                    done.
[100%] Project compiled successfully.
➜  pyplot-fortran git:(master) fpm test
pyplot_module.F90                      done.
libpyplot-fortran.a                    done.
test.f90                               done.
color_test.f90                         done.
test                                   done.
color_test                             done.
[100%] Project compiled successfully.
Traceback (most recent call last):
  File "/home/eelis/git/pyplot-fortran/test/errorbar.py", line 22, in <module>
    ax.errorbar(x,y,fmt=".",linewidth=3,markersize=3,label="y",xerr=xerr,yerr=yerr)
  File "/home/eelis/miniconda3/envs/kqcircuits/lib/python3.11/site-packages/matplotlib/__init__.py", line 1465, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eelis/miniconda3/envs/kqcircuits/lib/python3.11/site-packages/matplotlib/axes/_axes.py", line 3674, in error
bar
    raise ValueError(
ValueError: 'xerr' must not contain negative values

checking for python3

I'd vote for the module checking the command line starting with python3 if python fails. More and more recent OSes install only python3.x and do not provide python command at all.

pyplot-fortran on Raspberry Pi

pyplot-fortran works great on Raspberry Pi (Debian Linux "Stretch" Raspbian Nov 2017).
Python 2 is the default on the Pi, but ford fails under python 2. (annoying but not fatal).
To use with python3 the following software must first be installed:
$sudo apt-get install gfortran graphviz python3-matplotlib
$sudo pip3 install FoBiS.py ford

Download pyplot-fortran and extract to a folder of choice.
Edit pyplot_module.f90 using Geany IDE (installed). Modify lines 25 and 189 to
change 'python' to 'python3'.
Run the build.sh script. The module is created and may be used in fortran programs.
Now run the test program in /bin. Voila'! Check out the .png files and .py files .
TipOHat: The .py files can be modified and re-run! (make executable first).

Nice work Jacob. Thank you.

question of debugging

thank you for your project!
but I met a question when I was debugging. the result is as follows:
XX231F~`P6%LI}Q TJ @8RU

Extend matplotlib support

The present status is already useful in many situations, but it would be very appreciated a greater support for most of the matplotlib features.

Have you planned a road-map to extend the library?

Can I contribute? Do you accept PR? I can fork and try to add other matplotlib interfaces.

Compiling against python directly?

Python provides a C API, that lets you call python directly, I was wondering if you ever looked into this rather than using system calls to write out then execute python scripts.

Just starting to get into matplotlib myself, and was wondering if that might be an easier route for the end user... maybe not.

add topics

I suggest adding the topics plot, plotting in the About section so that searches like language:fortran topic:plotting display your project.

Persistent python script file

Hi Jacob,

using your great library I see that the python script used to generate the plots figure (and generated itself from pyplot-fortran) is persistent even if you do not specify a name for it into the savefig method. My expectation was that if I do not specify the name of the python script that file was not persistent, on the contrary if you do not specify the name the script file is simply named with a temporary name.

This is a design feature?

I like to avoid a default persistent script. Maybe a simple solution could to be use the close(...STATUS='delete) instead of close(...) into the execute method.

Raw string literals in labels and titles

Thank you for this incredibly useful project!

Problem description

When labels or titles are defined that contain escape sequences, Python/matplotlib does not render the TeX strings correctly, e.g.:

call plt%initialize(..., ylabel='$\frac{\bar{x}}{\bar{x}_0}$', title='normalised $\bar{x}$ values', ...)
...
call plt%add_plot(..., label='$\bar{x}_0 \neq 0$', ...)

This is because e.g. the \b, \f and \n are interpreted by Python as escape sequences for ASCII Backspace, ASCII Formfeed and ASCII Linefeed, respectively. At least, that is the case for me with Python 3.6, running on Ubuntu 18.04 via Windows Subsystem for Linux (WSL).

Possible solution

If the labels/titles are defined as raw string literals in Python notation, e.g. r"$\bar{x}_0 \neq 0$", this problem is avoided. This can be done by changing lines 261 - 264 in the initialize subroutine:

if (present(xlabel)) call me%add_str('ax.set_xlabel(r"'//trim(xlabel)//'")')
if (present(ylabel)) call me%add_str('ax.set_ylabel(r"'//trim(ylabel)//'")')
if (present(zlabel)) call me%add_str('ax.set_zlabel(r"'//trim(zlabel)//'")')
if (present(title))  call me%add_str('ax.set_title(r"' //trim(title) //'")')

and everywhere label is defined in add_*** subroutines for the different plot types (in lines 330, 411, 513, 603, 677 and 834):

'label=r"'//trim(label)//'")'

There may very well be reasons for not doing this, so I'm just wondering if this is a bug or a feature :-)

dpi

why did I make dpi a string, rather than an integer?

double check that.

Error stop

Eliminate the error stop calls if there is a problem. Replace with a status code.

plt_imshow

Hello,

I usually work with 2d data, mostly maps, and I thought you library would be nice to make some quick plots of my data instead of running the fortran code and then jump to python and make the same image.
Problem is my images are very big (3700x3700px) and your method of writing all pixels to the .py make it impossible for me to work.
I've implemented the method to call the imshow and for images of 1000x1000 it takes around +20s to run and produces a .py of +20MB, so it can be useful to someone if you want to add it to your code.
Anyway, this is a great job and is useful for more simple data.

Best regards,
Ricardo

    subroutine add_imshow(me, x)

    class(pyplot),          intent (inout)        :: me           !! pyplot handler
    real(wp),dimension(:,:),intent (in)           :: x            !! x values

    character(len=:), allocatable :: xstr         !! x values stringified
    character(len=*), parameter   :: xname = 'x'  !! x variable name for script

    if (allocated(me%str)) then

        !convert the arrays to strings:
        call matrix_to_string(x, me%real_fmt, xstr, me%use_numpy)

        !write the arrays:
        call me%add_str(trim(xname)//' = '//xstr)
        call me%add_str('')

        !write the plot statement:
        call me%add_str('ax.imshow  ('//&
                        trim(xname)//')')

        call me%add_str('')

    else
        error stop 'Error in add_imshow: pyplot class not properly initialized.'
    end if

    end subroutine add_imshow

Not standard error statement

Hi Jacob,

If I compile pyplot-fortran with a paranoiac debug mode I obtain some warnings like

src/tests/pyplot_module.f90(235): warning #6477: Fortran 2008 does not allow this statement or directive.
        error stop 'Error in add_plot: pyplot class not properly initialized.'
-------------------^

About 3d plot and meshgrid

Hi Jacob:

Is it possible to use pyplot-fortran to plot the meshgrid of xgrid and ygrid on the z(:, :) rather than just only able to plot an z(:) in the 3d space?

Thank you!

HJ

Issues with conversion of passed array to `color` in `add_plot`

So far I've had a great time with this package, as much as it becoming the main plotting backend of my new project HoneyTools. Now I wanted to switch away from the default matplotlib colors, so to have a plotting-style that is coherent with the logo and the general look of the project, but I encounter some tricky problems in doing that.


I define these two colors:

real(8), parameter :: F(3) = [0.4510d0, 0.3098d0, 0.5882d0] ! Fortran-lang color 
real(8), parameter :: Y(3) = [0.9608d0, 0.8157d0, 0.0118d0] ! HoneyTools' Yellow

And call add_plot as

! Sublattice "A"
call plt%add_plot(Ax,Ay,label='',linestyle='o',markersize=5,color=F)
! Sublattice "B"
call plt%add_plot(Bx,By,label='',linestyle='o',markersize=5,color=Y)

But I get the following runtime errors:

Traceback (most recent call last):
  File "/Users/gbellomia/Dropbox/SISSA/QcmPlab/HoneyTools/xy_plot.py", line 1648, in <module>
    ax.plot(x,y,"o",linewidth=3,markersize=5,label="",color=(0.49999999999999928,-1.0000000000000000,7.7942286340599480))
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 1635, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 312, in __call__
    yield from self._plot_args(this, kwargs)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in _plot_args
    return [l[0] for l in result]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in <listcomp>
    return [l[0] for l in result]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 531, in <genexpr>
    result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 351, in _makeline
    seg = mlines.Line2D(x, y, **kw)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 370, in __init__
    self.set_color(color)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 1030, in set_color
    mcolors._check_color_like(color=color)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/colors.py", line 130, in _check_color_like
    raise ValueError(f"{v!r} is not a valid value for {k}")
ValueError: (0.4999999999999993, -1.0, 7.794228634059948) is not a valid value for color
Traceback (most recent call last):
  File "/Users/gbellomia/Dropbox/SISSA/QcmPlab/HoneyTools/xy_plot.py", line 2248, in <module>
    ax.plot(x,y,"o",linewidth=3,markersize=5,label="",color=(0.49999999999999928,-1.0000000000000000,9.5262794416288248))
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 1635, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 312, in __call__
    yield from self._plot_args(this, kwargs)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in _plot_args
    return [l[0] for l in result]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in <listcomp>
    return [l[0] for l in result]
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 531, in <genexpr>
    result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
  File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 351, in _makeline
    seg = mlines.Line2D(x, y, **kw)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 370, in __init__
    self.set_color(color)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 1030, in set_color
    mcolors._check_color_like(color=color)
  File "/usr/local/lib/python3.10/site-packages/matplotlib/colors.py", line 130, in _check_color_like
    raise ValueError(f"{v!r} is not a valid value for {k}")
ValueError: (0.4999999999999993, -1.0, 9.526279441628825) is not a valid value for color

Which imo highlight a clear problem in real array to string conversion, as requested here:

if (present(color)) then
if (size(color)<=3) then
call vec_to_string(color(1:3), '*', color_str, use_numpy=.false., is_tuple=.true.)
arg_str = arg_str//',color='//trim(color_str)
end if
end if


An additional peculiar thing that I found is that the reported python runtime behavior happens if the -Wall flag is passed to fpm. Without it I get an obscure fortran runtime error:

At line 377 of file build/dependencies/pyplot-fortran/src/pyplot_module.F90
Fortran runtime error: Index '3' of dimension 1 of array 'color' outside of expected range (2:1)

How is the expected range (2:1) if I pass a dimension(3) array? Why does -Wall make me bypass the problem in Fortran (?! this really surprises me...) and get to the python exception? All this is quite strange to me and I have no idea of what could be happening, so I report it here, for documentation purposes.

Note: I saw that the color=[a,b,c] option in add_plot is currently not included in the CI test-suite. So this may be a long living problem here.

Use OO interface

I'd love to use your wonderful project, but unfortunately there is a blocking issue for me.

The current Python code uses matplotlib's GUI, which does not work for me. I have no graphical support, so Python gives me a RuntimeError: could not open display. This can easily happen working with remote servers, which I think is common for Fortran programmers.

The solution is to use matplotlib's OO API. So initialize a figure with matplotlib.figure.Figure, which, unlike matplotlib.pyplot.figure, does not try to open a window. The OO interface is also generally considered better style, and I imagine it might be faster.

This is addressed by pull request #22 .

RGB color

Add RGB input option for specifying line colors.

str variable cannot hold big data set

If you run the test with n say 20000
Then the program goes crazy because it seems the Fortran cannot handle such big data in allocatable string!

I propose to not write x,y data (numeric data) into str!

Visual Studio 2019

Jacob, have you tried to compile in Visual Studio 2019? I was wondering if there were any flags that need to be disabled to make it compile. Tried it an had some issues:

Severity Code Description Project File Line Suppression State
Error Compilation Aborted (code 1) C:\Users\don.dotson\source\repos\matplotlib\module.f90 1
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 36
Error error #6418: This name has already been assigned a data type. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 36
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 38
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 40
Error Compilation Aborted (code 1) C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 1
Error error #7002: Error in opening the compiled module file. Check INCLUDE paths. [PYPLOT_MODULE] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 4
Error error #6457: This derived type name has not been declared. [PYPLOT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 9
Error error #6404: This name does not have a type, and must have an explicit type. [PLT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 17
Error error #6460: This is not a component name that is defined in the encompassing structure. [INITIALIZE] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 17
Error error #6460: This is not a component name that is defined in the encompassing structure. [ADD_PLOT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 19
Error error #6460: This is not a component name that is defined in the encompassing structure. [SAVEFIG] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.