Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "lineStyle" arguments #59

Closed
bukkideme opened this issue Jul 30, 2019 · 22 comments
Closed

support "lineStyle" arguments #59

bukkideme opened this issue Jul 30, 2019 · 22 comments
Assignees

Comments

@bukkideme
Copy link
Contributor

You already implemented selectable marker shapes for Plots, which is great! What do you think, could it be possible to also implement dashed line types (like dotted, dash, dash/dots, etc)?
In this case, I think the legend section could automatically show marker shapes / line types, depending on the following conditions:

  1. We have larger than zero for both marker shapes and line widths: show both markers and (dashed) lines in legend section.
  2. If either the line width or the marker shape zero valued, reflect this info in legend: for example in case of zero sized marker, only show line. In the recent Legend behavior, the marker shows up even if we only plot the line and set marker size to zero.

I will really try to find some time later on to do some real contribution to the code base, sorry that recently I can only provide such limited help...

@swharden
Copy link
Member

It would be great to be able to plot dotted, dashed, and other patterns of lines. I think the only plottable objects which would benefit from this are scatter plots and axis lines.

This should be easy to implement too. Lines are drawn with Pen objects. These objects are created here for scatter plots and here for axis lines. Pen objects are currently all set to draw solid lines, but they can be easily customized to draw different patterns by setting their DashStyle:

pen.DashStyle = DashStyle.DashDot;

Once implemented, the legend code could be updated to draw proper dash styles too.

The website
http://csharphelper.com/blog/2015/02/draw-dashed-lines-with-different-styles-in-c/ displays some common styles:

image

@Padanian
Copy link
Contributor

Padanian commented Jul 30, 2019 via email

@Padanian
Copy link
Contributor

Padanian commented Jul 30, 2019 via email

@swharden
Copy link
Member

The legend could just show line (with its DashStyle) and place a single marker above it (if markers are being used).

# python example
import matplotlib.pyplot as plt
import numpy as np
xs = np.arange(20)
ys = np.sin(np.pi*2*xs/len(xs))
plt.plot(xs, ys, label='data', linestyle=':',
    marker='v', markerfacecolor='r', markeredgewidth=0)
plt.legend()
plt.show()

image

@Padanian
Copy link
Contributor

Padanian commented Jul 30, 2019 via email

@swharden
Copy link
Member

@Padanian did you try to post a picture with your last message? I'm viewing the GitHub issue page #59 and no image appeared with your last post.

@Padanian
Copy link
Contributor

Yes, this one
immagine
Do I need to redefine dashes and spaces?

@swharden
Copy link
Member

It looks like a pretty good start! Let's add some custom dash patterns into the mix so we can always add/modify patterns later. I think you make custom patterns like:

Pen pen = new Pen(Color.Black, 5);
float[] dashValues = { 5, 2, 15, 4 };
pen.DashPattern = dashValues;

image

@swharden
Copy link
Member

... actually, maybe all our patterns should be custom? Maybe the dash values are some multiple of line width?

@Padanian
Copy link
Contributor

Padanian commented Jul 30, 2019 via email

@Padanian
Copy link
Contributor

immagine

@swharden
Copy link
Member

Yes, all of them need to be custom, to properly render. I’m working on it. Will commit later tonight.

Sounds great! Thanks for your contribution! It's looking great already.

@bukkideme
Copy link
Contributor Author

Another thing I noticed about Legends, sometimes it could be useful to change their size / font type. As for example, we have in the case of the PlotText() method.
The "fontName", "fontSize", "bold" inputs could be also very useful for the Legend() method. What do you think, when we increase/decrease font size in a legend, should the legend markers follow these size changes too? I guess it would look nicer...

@swharden
Copy link
Member

A review of fonts for the title, axis labels, legend, and PlotText() is a good idea! Some of these features are implemented and some aren't, but a review of each of these methods to fill-in the missing features and ensure consistency would be an improvement for sure. I started an issue devoted to this topic #61

Regarding the marker size in the legend, I think it should reflect the marker size in the plot itself. Scatter plots could code plot groups by marker size, so since that may be its own metric let's stick to drawing it "actual size" in the legend.

@swharden
Copy link
Member

Regarding the marker size in the legend, I think it should reflect the marker size in the plot itself. Scatter plots could code plot groups by marker size, so since that may be its own metric let's stick to drawing it "actual size" in the legend.

This also makes me think we should probably should draw the lines in the legend as their actual size, since lineWidth might be used to separate groups of data... @Padanian do you want to make this change?

@Padanian
Copy link
Contributor

Padanian commented Jul 31, 2019 via email

@Padanian
Copy link
Contributor

Padanian commented Jul 31, 2019 via email

@bukkideme
Copy link
Contributor Author

It'll be awful. Been there, done that. That's why I set it to fixed linewidth.

I also think that line width in Legend does not need to match the plotted line width. Same applies to symbol/marker size. However, if we increase the font size (option will be in a later release) in the Legend, the marker/line symbols might become unproportionally small compared to it. Should the marker/line symbol size be scaled with the Legend font size? What do you think?

Actually the visibility of the Legend marker next to the text in the recent version also feels a little bit small, difficult to see the colored dots front of the Legend text lines...
example1

@Padanian
Copy link
Contributor

Padanian commented Aug 1, 2019 via email

@swharden swharden changed the title Implementing Plot line types, enhance Legend symbols support "lineStyle" arguments (and display lineStyle in legend) Aug 3, 2019
@swharden swharden changed the title support "lineStyle" arguments (and display lineStyle in legend) support "lineStyle" arguments Aug 3, 2019
@Padanian
Copy link
Contributor

Padanian commented Aug 3, 2019

Marker size to reflect legend font size is ready to request pull, but you already got a pull request ahead. Please pull it before this or delete it.

@swharden
Copy link
Member

swharden commented Aug 3, 2019

Just pulled @Padanian's branch into the master (#60). I called the argument "lineStyle" to be consistent with matplotlib's naming convention. I also added an example to the cookbook:

https://github.com/swharden/ScottPlot/tree/master/cookbook#custom-linestyles

Thanks @Padanian!

@swharden swharden closed this as completed Aug 3, 2019
@marc-frank
Copy link

Hi, I used this:
formsPlot1.Plot.AddCircle(x: midpoint.X, y: midpoint.Y, radius: radius, color: Color.Gray, lineWidth: 1, lineStyle: ScottPlot.LineStyle.Dash);
But the line draws solid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants