pyplot can be fun.

As an alternative to
a, b = [], []
for x in range(-50,50):
    y=x**2
    a.append(x)
    b.append(y) 

this is shorter and probably a little easier to grasp what the variables 
represent:

xy = [(x, x**2) for x in range(-50, 50)]
x, y = zip(*xy)  # type(x) is a tuple

I also recommend you develop a set of styles you like and save them to a 
style file in a known place.  The you can apply its styles to each graph 
like this:

plt.style.use(style_file)

Here is one of mine:

axes.facecolor: white
axes.grid : True

text.hinting_factor : 8
xtick.direction: out
ytick.direction: out

grid.color: lightgrey
grid.linestyle: -    # solid line

figure.facecolor: (.90,.90,.90)
figure.edgecolor: 0.50
figure.figsize: 8, 5.5

axes.prop_cycle: cycler('color', ['black', 'lightgrey', 'indigo', 'red', 
'blue', 'cyan', 'gray', 'magenta'])

mathtext.fontset : stix

You might want to check out plotnine, too, for plotting your datasets. You 
install it with pip.

Another fun little goodie is the attached outline.  It contains a command 
that plots in a new tab in the log frame.
On Tuesday, December 17, 2024 at 10:14:21 AM UTC-5 Edward K. Ream wrote:

> On Saturday, December 14, 2024 at 4:46:59 AM UTC-6 Edward K. Ream wrote:
>
> On second thought, the title of this thread is misguided.
>
>
> I have spent the last week coming up to speed on all the fabulous math 
> tools and websites out there.
>
> This morning I finally got around to writing my first matplotlib program. 
> See the Postscript. 
> This exercise has been a ton of fun. execute-script just works!
>
> For me, Leo *is *the perfect platform for running Matplotlib programs.
> The more I use Jupyter, the less I like it, so the title of this thread 
> seems about right :-)
>
> Edward
>
> P.S. Here is my first plot:
>
> import matplotlib.pyplot as plt
> import numpy as np
>
> # Use a monospace font for 
> plt.rcParams["font.family"] = 'DejaVu Sans Mono'
>
> a, b = [], []
> for x in range(-50,50):
>     y=x**2
>     a.append(x)
>     b.append(y)
>
> fig= plt.figure()
> fig.suptitle('Parabola with Tangents')
> axes=fig.add_subplot()
> axes.plot(a,b)
>
> # Cut the tangent lines off at y = 0
> plt.ylim(bottom=0)
> color = iter(plt.cm.rainbow(np.linspace(0, 1, 6)))
> for i, x in enumerate(range(-50, 60, 20)):
>     if x == 0:
>         continue
>     y = x**2
>     slope = 2 * x
>     x_y_s = f"({x:3}, {y})"
>     label = f"{x_y_s:<11} slope: {slope:4}, x-intercept: {x - y/slope:>5}"
>     plt.axline((x, y), slope=slope, label=label, c=next(color))
> axes.legend()
> fig.canvas.manager.window.move(50,50)  # Move the window.
> plt.show()
>
> EKR
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/leo-editor/8312accc-f690-47ba-81a3-e8314b7b2736n%40googlegroups.com.

<<attachment: matplotlib-plot-in-tab.zip>>

Reply via email to